diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-03-11 00:48:35 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-03-11 00:48:35 +0100 |
commit | 48b0c10681bb4e0785fa9f737d287531d06fecb7 (patch) | |
tree | 568f7cdd23400f1e781b82aa044ad39748ff9d78 /sys/src/ape/lib/ap/stdio/rdline.c | |
parent | 530a2bc5e99ad83c46ce015544cf30173c145bcc (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/rdline.c')
-rw-r--r-- | sys/src/ape/lib/ap/stdio/rdline.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sys/src/ape/lib/ap/stdio/rdline.c b/sys/src/ape/lib/ap/stdio/rdline.c index 6281a97e8..dafe71da4 100644 --- a/sys/src/ape/lib/ap/stdio/rdline.c +++ b/sys/src/ape/lib/ap/stdio/rdline.c @@ -12,7 +12,8 @@ char *rdline(FILE *f, char **ep){ default: /* CLOSED, WR, ERR, EOF */ return NULL; case OPEN: - _IO_setvbuf(f); + if(_IO_setvbuf(f)!=0) + return NULL; case RDWR: f->state=RD; case RD: @@ -46,6 +47,8 @@ char *rdline(FILE *f, char **ep){ break; } cnt=read(f->fd, f->wp, cnt); + if(f->state==CLOSED) + return NULL; if(cnt==-1){ f->state=ERR; return NULL; |