1 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
2 #include <msvcrt/stdio.h>
3 #include <msvcrt/string.h>
4 #include <msvcrt/stdlib.h>
5 #include <msvcrt/internal/file.h>
8 FILE * __alloc_file(void);
10 char __validfp (FILE *f)
12 if ( (unsigned int)f < 256)
15 if( f == NULL || (int)f== -1 )
21 /* A FILE* is considered "free" if its flag is zero. */
23 FILE *__alloc_file(void)
25 __file_rec *fr = __file_rec_list;
26 __file_rec **last_fr = &__file_rec_list;
30 /* Try to find an empty slot */
33 last_fr = &(fr->next);
35 /* If one of the existing slots is available, return it */
36 for (i=0; i<fr->count; i++)
38 if (fr->files[i]->_flag == 0)
44 /* If this one is full, go to the next */
45 if (fr->count == __FILE_REC_MAX)
48 /* it isn't full, we can add to it */
53 /* add another one to the end, make it empty */
54 fr = *last_fr = (__file_rec *)malloc(sizeof(__file_rec));
60 /* fr is a pointer to a rec with empty slots in it */
61 rv = fr->files[fr->count] = (FILE *)malloc(sizeof(FILE));
64 memset(rv, 0, sizeof(FILE));
70 int _fcloseall( void )
72 __file_rec *fr = __file_rec_list;
73 __file_rec **last_fr = &__file_rec_list;
78 /* Try to find an empty slot */
81 last_fr = &(fr->next);
83 /* If one of the existing slots is available, return it */
84 for (i=0; i<fr->count; i++)
85 if (fr->files[i]->_flag != 0) {
90 /* If this one is full, go to the next */
91 if (fr->count == __FILE_REC_MAX)
94 /* it isn't full, we can add to it */