fopen.c - scc - simple c99 compiler
(HTM) git clone git://git.simple-cc.org/scc
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
fopen.c (380B)
---
1 #include <errno.h>
2 #include <stdio.h>
3
4 #include "../libc.h"
5
6 #undef fopen
7
8 FILE *
9 fopen(const char * restrict name, const char * restrict mode)
10 {
11 FILE *fp;
12
13 for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) {
14 if ((fp->flags & (_IOREAD | _IOWRITE | _IORW)) == 0)
15 break;
16 }
17 if (fp == &__iob[FOPEN_MAX]) {
18 errno = ENOMEM;
19 return NULL;
20 }
21
22 return _fpopen(name, mode, fp);
23 }