OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 1990 The Regents of the University of California. | 2 * Copyright (c) 1990 The Regents of the University of California. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms are permitted | 5 * Redistribution and use in source and binary forms are permitted |
6 * provided that the above copyright notice and this paragraph are | 6 * provided that the above copyright notice and this paragraph are |
7 * duplicated in all such forms and that any documentation, | 7 * duplicated in all such forms and that any documentation, |
8 * advertising materials, and other materials related to such | 8 * advertising materials, and other materials related to such |
9 * distribution and use acknowledge that the software was developed | 9 * distribution and use acknowledge that the software was developed |
10 * by the University of California, Berkeley. The name of the | 10 * by the University of California, Berkeley. The name of the |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 * Find a free FILE for fopen et al. | 100 * Find a free FILE for fopen et al. |
101 */ | 101 */ |
102 | 102 |
103 FILE * | 103 FILE * |
104 _DEFUN(__sfp, (d), | 104 _DEFUN(__sfp, (d), |
105 struct _reent *d) | 105 struct _reent *d) |
106 { | 106 { |
107 FILE *fp; | 107 FILE *fp; |
108 int n; | 108 int n; |
109 struct _glue *g; | 109 struct _glue *g; |
| 110 int found_fp = 0; |
110 | 111 |
111 CHECK_INIT(_GLOBAL_REENT, NULL); | 112 CHECK_INIT(_GLOBAL_REENT, NULL); |
112 | 113 |
113 __sfp_lock_acquire (); | 114 __sfp_lock_acquire (); |
114 | 115 |
115 for (g = &_GLOBAL_REENT->__sglue;; g = g->_next) | 116 for (g = &_GLOBAL_REENT->__sglue;; g = g->_next) |
116 { | 117 { |
117 for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) | 118 for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) |
118 » if (fp->_flags == 0) | 119 » { |
119 » goto found; | 120 » _flockfile(fp); |
| 121 » found_fp = (fp->_flags == 0); |
| 122 » _funlockfile(fp); |
| 123 » if (found_fp) |
| 124 » goto found; |
| 125 » } |
120 if (g->_next == NULL && | 126 if (g->_next == NULL && |
121 (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) | 127 (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) |
122 break; | 128 break; |
123 } | 129 } |
124 __sfp_lock_release (); | 130 __sfp_lock_release (); |
125 d->_errno = ENOMEM; | 131 d->_errno = ENOMEM; |
126 return NULL; | 132 return NULL; |
127 | 133 |
128 found: | 134 found: |
129 fp->_file = -1; /* no file */ | 135 fp->_file = -1; /* no file */ |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 303 } |
298 | 304 |
299 _VOID | 305 _VOID |
300 _DEFUN_VOID(__fp_unlock_all) | 306 _DEFUN_VOID(__fp_unlock_all) |
301 { | 307 { |
302 _CAST_VOID _fwalk (_REENT, __fp_unlock); | 308 _CAST_VOID _fwalk (_REENT, __fp_unlock); |
303 | 309 |
304 __sfp_lock_release (); | 310 __sfp_lock_release (); |
305 } | 311 } |
306 #endif | 312 #endif |
OLD | NEW |