ref: ca35949c20cee081efe5cda03bfff64167da05d2
parent: 52153c32dcc83b2ae752431f7827ddff9b926a78
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed May 28 20:34:47 EDT 2014
ape/stdio: set errno to EMFILE when running out of streams
--- a/sys/src/ape/lib/ap/stdio/_IO_newfile.c
+++ b/sys/src/ape/lib/ap/stdio/_IO_newfile.c
@@ -5,6 +5,7 @@
#define _PLAN9_SOURCE
#include <lock.h>
+#include <errno.h>
FILE *_IO_newfile(void)
{
@@ -21,7 +22,9 @@
}
f = fx;
unlock(&fl);
- if(f->state!=CLOSED)
+ if(f->state!=CLOSED){
+ errno = EMFILE;
return NULL;
+ }
return f;
}
--- 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;