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/fwrite.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/fwrite.c')
-rw-r--r-- | sys/src/ape/lib/ap/stdio/fwrite.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/src/ape/lib/ap/stdio/fwrite.c b/sys/src/ape/lib/ap/stdio/fwrite.c index 4dc18d99e..2ec20cae5 100644 --- a/sys/src/ape/lib/ap/stdio/fwrite.c +++ b/sys/src/ape/lib/ap/stdio/fwrite.c @@ -12,7 +12,7 @@ size_t fwrite(const void *p, size_t recl, size_t nrec, FILE *f){ s=(char *)p; n=recl*nrec; - while(n>0){ + while(n>0 && f->state!=CLOSED){ d=f->rp-f->wp; if(d>0){ if(d>n) @@ -26,7 +26,8 @@ size_t fwrite(const void *p, size_t recl, size_t nrec, FILE *f){ if(f->flags&APPEND) lseek(f->fd, 0L, SEEK_END); if(write(f->fd, f->buf, d)!=d){ - f->state=ERR; + if(f->state!=CLOSED) + f->state=ERR; goto ret; } f->wp=f->rp=f->buf; @@ -35,7 +36,8 @@ size_t fwrite(const void *p, size_t recl, size_t nrec, FILE *f){ lseek(f->fd, 0L, SEEK_END); d=write(f->fd, s, n); if(d<=0){ - f->state=ERR; + if(f->state!=CLOSED) + f->state=ERR; goto ret; } } else { |