4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "streams_array.h"
30 #include "streams_common.h"
33 * Single-byte character memory map-based streams implementation
37 stream_array_prime(stream_t
*str
)
39 ASSERT((str
->s_status
& STREAM_SOURCE_MASK
) == STREAM_ARRAY
);
41 str
->s_type
.LA
.s_cur_index
= MIN(0, str
->s_type
.LA
.s_array_size
- 1);
42 if (str
->s_type
.LA
.s_cur_index
>= 0)
44 str
->s_type
.LA
.s_array
[str
->s_type
.LA
.s_cur_index
],
47 stream_set(str
, STREAM_EOS_REACHED
);
48 stream_unset(str
, STREAM_PRIMED
);
49 return (PRIME_FAILED_EMPTY_FILE
);
52 stream_set(str
, STREAM_PRIMED
);
54 return (PRIME_SUCCEEDED
);
58 stream_array_fetch(stream_t
*str
)
60 ASSERT(str
->s_status
& STREAM_OPEN
);
61 ASSERT(str
->s_type
.LA
.s_cur_index
< str
->s_type
.LA
.s_array_size
);
63 if (++str
->s_type
.LA
.s_cur_index
== str
->s_type
.LA
.s_array_size
- 1)
64 stream_set(str
, STREAM_EOS_REACHED
);
66 copy_line_rec(str
->s_type
.LA
.s_array
[str
->s_type
.LA
.s_cur_index
],
69 return (NEXT_LINE_COMPLETE
);
74 stream_array_is_closable(stream_t
*str
)
77 * Array streams are not closable. That is, there is no open file
78 * descriptor directly associated with an array stream.
84 stream_array_close(stream_t
*str
)
86 stream_unset(str
, STREAM_OPEN
| STREAM_PRIMED
);
92 stream_array_free(stream_t
*str
)
95 * It's now safe for us to close the various streams backing the array
98 stream_unset(str
, STREAM_PRIMED
| STREAM_NOT_FREEABLE
);
104 stream_array_eos(stream_t
*str
)
108 if (str
== NULL
|| str
->s_status
& STREAM_EOS_REACHED
)
111 if (str
->s_type
.LA
.s_cur_index
+ 1 >= str
->s_type
.LA
.s_array_size
) {
113 stream_set(str
, STREAM_EOS_REACHED
);
121 stream_array_release_line(stream_t
*str
)
125 const stream_ops_t stream_array_ops
= {
126 stream_array_is_closable
,
135 stream_array_release_line
,