diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-29 00:34:47 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-29 00:34:47 +0200 |
commit | ca35949c20cee081efe5cda03bfff64167da05d2 (patch) | |
tree | 064e22a4acc0d7a6b513926ca46a7fa346f9b682 /sys/src/ape/lib/ap/stdio/fdopen.c | |
parent | 52153c32dcc83b2ae752431f7827ddff9b926a78 (diff) |
ape/stdio: set errno to EMFILE when running out of streams
Diffstat (limited to 'sys/src/ape/lib/ap/stdio/fdopen.c')
-rw-r--r-- | sys/src/ape/lib/ap/stdio/fdopen.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sys/src/ape/lib/ap/stdio/fdopen.c b/sys/src/ape/lib/ap/stdio/fdopen.c index cb10d98e7..b3061fbe7 100644 --- a/sys/src/ape/lib/ap/stdio/fdopen.c +++ b/sys/src/ape/lib/ap/stdio/fdopen.c @@ -2,6 +2,7 @@ * Posix stdio -- fdopen */ #include "iolib.h" +#include <errno.h> /* * Open the named file with the given mode, using the given FILE * Legal modes are given below, `additional characters may follow these sequences': @@ -15,12 +16,15 @@ FILE *fdopen(const int fd, const char *mode){ FILE *f; + if(fd < 0){ + errno = EBADF; + return NULL; + } if((f = _IO_newfile()) == NULL) return NULL; f->fd=fd; if(mode[0]=='a') lseek(f->fd, 0L, 2); - if(f->fd==-1) return NULL; f->flags=0; f->state=OPEN; f->buf=0; |