fopen.c (403B)
1 #include <errno.h> 2 #include <stdio.h> 3 4 #include "../syscall.h" 5 #include "../libc.h" 6 #undef fopen 7 8 9 FILE * 10 fopen(const char * restrict name, const char * restrict mode) 11 { 12 FILE *fp; 13 14 for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) { 15 if ((fp->flags & (_IOREAD | _IOWRITE | _IORW)) == 0) 16 break; 17 } 18 if (fp == &__iob[FOPEN_MAX]) { 19 errno = ENOMEM; 20 return NULL; 21 } 22 return _fpopen(name, mode, fp); 23 }