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 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
41 static fifobuffer_t
**FifoBufferTable
= NULL
;
42 static int FifoBufferTableSize
= 0;
47 static int InitFifoBufferTable (void);
48 static int GrowFifoBufferTable (int);
49 static fifobuffer_t
*NewFifoBuffer (int);
53 ResetFifoBuffer(int fd
)
55 if ((!FifoBufferTableSize
) && (InitFifoBufferTable () < 0))
58 if (fd
>= FifoBufferTableSize
)
61 if (FifoBufferTable
[fd
]) {
62 FifoBufferTable
[fd
]->full
= 0;
63 FifoBufferTable
[fd
]->psave
=
64 FifoBufferTable
[fd
]->psave_end
=
65 FifoBufferTable
[fd
]->save
;
78 if ((fd
>= FifoBufferTableSize
) && (GrowFifoBufferTable (fd
) < 0))
81 if (!FifoBufferTable
[fd
]) {
82 if (!NewFifoBuffer (fd
))
85 FifoBufferTable
[fd
]->full
= 0;
86 FifoBufferTable
[fd
]->psave
=
87 FifoBufferTable
[fd
]->psave_end
=
88 FifoBufferTable
[fd
]->save
;
91 return FifoBufferTable
[fd
];
98 if (FifoBufferTableSize
)
101 FifoBufferTable
= (fifobuffer_t
**)
102 Calloc (100, sizeof (fifobuffer_t
*));
103 if (!FifoBufferTable
)
104 return -1; /* ENOMEM is already set. */
106 FifoBufferTableSize
= 100;
113 GrowFifoBufferTable (int fd
)
115 fifobuffer_t
**newpp
;
117 newpp
= (fifobuffer_t
**)
118 Realloc ((void*)FifoBufferTable
,
119 (fd
+10)*sizeof (fifobuffer_t
*));
121 return -1; /* ENOMEM is already set. */
123 FifoBufferTableSize
= fd
+10;
129 static fifobuffer_t
*
130 NewFifoBuffer(int fd
)
134 for (i
=0; i
< FifoBufferTableSize
; i
++)
136 if (FifoBufferTable
[i
] &&
137 Fcntl (i
, F_GETFL
) < 0 &&
140 FifoBufferTable
[fd
] = FifoBufferTable
[i
];
141 FifoBufferTable
[i
] = NULL
;
142 return FifoBufferTable
[fd
];
145 FifoBufferTable
[fd
] = (fifobuffer_t
*)
146 Calloc (1, sizeof (fifobuffer_t
));
148 return FifoBufferTable
[fd
];