
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.
32 lines
588 B
C
32 lines
588 B
C
/*
|
|
* pANS stdio -- fflush
|
|
*/
|
|
#include "iolib.h"
|
|
int fflush(FILE *f){
|
|
int error, cnt;
|
|
if(f==NULL){
|
|
error=0;
|
|
for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++)
|
|
if(f->state==WR && fflush(f)==EOF)
|
|
error=EOF;
|
|
return error;
|
|
}
|
|
if(f->flags&STRING) return EOF;
|
|
switch(f->state){
|
|
default: /* OPEN RDWR EOF RD */
|
|
return 0;
|
|
case CLOSED:
|
|
case ERR:
|
|
return EOF;
|
|
case WR:
|
|
cnt=(f->flags&LINEBUF?f->lp:f->wp)-f->buf;
|
|
if(cnt && write(f->fd, f->buf, cnt)!=cnt){
|
|
if(f->state!=CLOSED)
|
|
f->state=ERR;
|
|
return EOF;
|
|
}
|
|
f->rp=f->wp=f->buf;
|
|
f->state=RDWR;
|
|
return 0;
|
|
}
|
|
}
|