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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 * Find a free FILE for fopen et al. | 108 * Find a free FILE for fopen et al. |
109 */ | 109 */ |
110 | 110 |
111 FILE * | 111 FILE * |
112 _DEFUN(__sfp, (d), | 112 _DEFUN(__sfp, (d), |
113 struct _reent *d) | 113 struct _reent *d) |
114 { | 114 { |
115 FILE *fp; | 115 FILE *fp; |
116 int n; | 116 int n; |
117 struct _glue *g; | 117 struct _glue *g; |
118 int found_fp = 0; | |
119 | 118 |
120 CHECK_INIT(_GLOBAL_REENT, NULL); | 119 CHECK_INIT(_GLOBAL_REENT, NULL); |
121 | 120 |
122 _newlib_sfp_lock_start (); | 121 _newlib_sfp_lock_start (); |
123 | 122 |
124 for (g = &_GLOBAL_REENT->__sglue;; g = g->_next) | 123 for (g = &_GLOBAL_REENT->__sglue;; g = g->_next) |
125 { | 124 { |
126 for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) | 125 for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) |
127 » { | 126 » if (fp->_flags == 0) |
128 » _flockfile(fp); | 127 » goto found; |
129 » found_fp = (fp->_flags == 0); | |
130 » _funlockfile(fp); | |
131 » if (found_fp) | |
132 » goto found; | |
133 » } | |
134 if (g->_next == NULL && | 128 if (g->_next == NULL && |
135 (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) | 129 (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) |
136 break; | 130 break; |
137 } | 131 } |
138 _newlib_sfp_lock_exit (); | 132 _newlib_sfp_lock_exit (); |
139 d->_errno = ENOMEM; | 133 d->_errno = ENOMEM; |
140 return NULL; | 134 return NULL; |
141 | 135 |
142 found: | 136 found: |
143 fp->_file = -1; /* no file */ | 137 fp->_file = -1; /* no file */ |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 311 } |
318 | 312 |
319 _VOID | 313 _VOID |
320 _DEFUN_VOID(__fp_unlock_all) | 314 _DEFUN_VOID(__fp_unlock_all) |
321 { | 315 { |
322 _CAST_VOID _fwalk (_REENT, __fp_unlock); | 316 _CAST_VOID _fwalk (_REENT, __fp_unlock); |
323 | 317 |
324 __sfp_lock_release (); | 318 __sfp_lock_release (); |
325 } | 319 } |
326 #endif | 320 #endif |
OLD | NEW |