8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sort / common / streams_array.c
blob29afd424cc480be720320793f0cb46e2ad4bb6bc
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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
36 static int
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)
43 copy_line_rec(
44 str->s_type.LA.s_array[str->s_type.LA.s_cur_index],
45 &str->s_current);
46 else {
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);
57 static ssize_t
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],
67 &str->s_current);
69 return (NEXT_LINE_COMPLETE);
72 /*ARGSUSED*/
73 static int
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.
80 return (0);
83 static int
84 stream_array_close(stream_t *str)
86 stream_unset(str, STREAM_OPEN | STREAM_PRIMED);
88 return (1);
91 static int
92 stream_array_free(stream_t *str)
95 * It's now safe for us to close the various streams backing the array
96 * stream's data.
98 stream_unset(str, STREAM_PRIMED | STREAM_NOT_FREEABLE);
100 return (1);
103 static int
104 stream_array_eos(stream_t *str)
106 int retval = 0;
108 if (str == NULL || str->s_status & STREAM_EOS_REACHED)
109 return (1);
111 if (str->s_type.LA.s_cur_index + 1 >= str->s_type.LA.s_array_size) {
112 retval = 1;
113 stream_set(str, STREAM_EOS_REACHED);
116 return (retval);
119 /*ARGSUSED*/
120 static void
121 stream_array_release_line(stream_t *str)
125 const stream_ops_t stream_array_ops = {
126 stream_array_is_closable,
127 stream_array_close,
128 stream_array_eos,
129 stream_array_fetch,
130 NULL,
131 stream_array_free,
132 NULL,
133 stream_array_prime,
134 NULL,
135 stream_array_release_line,
136 NULL,
137 NULL