summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/stdio/_IO_getc.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-03-11 00:48:35 +0100
committercinap_lenrek <cinap_lenrek@gmx.de>2013-03-11 00:48:35 +0100
commit48b0c10681bb4e0785fa9f737d287531d06fecb7 (patch)
tree568f7cdd23400f1e781b82aa044ad39748ff9d78 /sys/src/ape/lib/ap/stdio/_IO_getc.c
parent530a2bc5e99ad83c46ce015544cf30173c145bcc (diff)
ape/stdio: make fopen() quasi threadsafe for python
python uses processes sharing memory. it requires at least fopen() to be called by multiple threads at once so we introduce _IO_newfile() which allocates the FILE structure slot under a lock.
Diffstat (limited to 'sys/src/ape/lib/ap/stdio/_IO_getc.c')
-rw-r--r--sys/src/ape/lib/ap/stdio/_IO_getc.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/src/ape/lib/ap/stdio/_IO_getc.c b/sys/src/ape/lib/ap/stdio/_IO_getc.c
index 3f99922c2..fbd126df3 100644
--- a/sys/src/ape/lib/ap/stdio/_IO_getc.c
+++ b/sys/src/ape/lib/ap/stdio/_IO_getc.c
@@ -8,7 +8,7 @@ int _IO_getc(FILE *f){
default: /* CLOSED, WR, ERR, EOF */
return EOF;
case OPEN:
- _IO_setvbuf(f);
+ if(_IO_setvbuf(f)!=0) return EOF;
case RDWR:
case RD:
if(f->flags&STRING) return EOF;
@@ -17,6 +17,7 @@ int _IO_getc(FILE *f){
else
n = f->bufl;
cnt=read(f->fd, f->buf, n);
+ if(f->state==CLOSED) return EOF;
switch(cnt){
case -1: f->state=ERR; return EOF;
case 0: f->state=END; return EOF;