ape/stdio: set errno to EMFILE when running out of streams

This commit is contained in:
cinap_lenrek 2014-05-29 00:34:47 +02:00
parent 52153c32dc
commit ca35949c20
2 changed files with 9 additions and 2 deletions

View file

@ -5,6 +5,7 @@
#define _PLAN9_SOURCE #define _PLAN9_SOURCE
#include <lock.h> #include <lock.h>
#include <errno.h>
FILE *_IO_newfile(void) FILE *_IO_newfile(void)
{ {
@ -21,7 +22,9 @@ FILE *_IO_newfile(void)
} }
f = fx; f = fx;
unlock(&fl); unlock(&fl);
if(f->state!=CLOSED) if(f->state!=CLOSED){
errno = EMFILE;
return NULL; return NULL;
}
return f; return f;
} }

View file

@ -2,6 +2,7 @@
* Posix stdio -- fdopen * Posix stdio -- fdopen
*/ */
#include "iolib.h" #include "iolib.h"
#include <errno.h>
/* /*
* Open the named file with the given mode, using the given FILE * Open the named file with the given mode, using the given FILE
* Legal modes are given below, `additional characters may follow these sequences': * Legal modes are given below, `additional characters may follow these sequences':
@ -15,12 +16,15 @@
FILE *fdopen(const int fd, const char *mode){ FILE *fdopen(const int fd, const char *mode){
FILE *f; FILE *f;
if(fd < 0){
errno = EBADF;
return NULL;
}
if((f = _IO_newfile()) == NULL) if((f = _IO_newfile()) == NULL)
return NULL; return NULL;
f->fd=fd; f->fd=fd;
if(mode[0]=='a') if(mode[0]=='a')
lseek(f->fd, 0L, 2); lseek(f->fd, 0L, 2);
if(f->fd==-1) return NULL;
f->flags=0; f->flags=0;
f->state=OPEN; f->state=OPEN;
f->buf=0; f->buf=0;