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 1987 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
38 #define active(iop) ((iop)->_flag & (_IOREAD|_IOWRT|_IORW))
40 static unsigned char sbuf
[NSTATIC
][_SBFSIZ
];
41 unsigned char (*_smbuf
)[_SBFSIZ
] = sbuf
;
42 static FILE **iobglue
;
43 static FILE **endglue
;
46 * Find a free FILE for fopen et al.
47 * We have a fixed static array of entries, and in addition
48 * may allocate additional entries dynamically, up to the kernel
49 * limit on the number of open files.
50 * At first just check for a free slot in the fixed static array.
51 * If none are available, then we allocate a structure to glue together
52 * the old and new FILE entries, which are then no longer contiguous.
61 for(iop
= _iob
; iop
< _iob
+ NSTATIC
; iop
++)
65 if(_f_morefiles() == 0) {
72 while(*iov
!= NULL
&& active(*iov
))
73 if (++iov
>= endglue
) {
79 *iov
= (FILE *)calloc(1, sizeof **iov
);
92 nfiles
= getdtablesize();
94 iobglue
= (FILE **)calloc(nfiles
, sizeof *iobglue
);
98 if((_smbuf
= (unsigned char (*)[_SBFSIZ
])malloc(nfiles
* sizeof *_smbuf
)) == NULL
) {
99 free((char *)iobglue
);
104 endglue
= iobglue
+ nfiles
;
106 for(fp
= _iob
, iov
= iobglue
; fp
< &_iob
[NSTATIC
]; /* void */)
118 if(iobglue
== NULL
&& _f_morefiles() == 0)
121 for(iov
= iobglue
; iov
< endglue
; iov
++)
123 *iov
= (FILE *)calloc(1, sizeof **iov
);
127 _fwalk(int (*function
)(FILE *))
135 if(iobglue
== NULL
) {
136 for(fp
= _iob
; fp
< &_iob
[NSTATIC
]; fp
++)
140 for(iov
= iobglue
; iov
< endglue
; iov
++)
141 if(*iov
&& active(*iov
))