1#include <errno.h>2#include <stdio.h>34#include "../libc.h"5#include "../syscall.h"67int8_flsbuf(FILE *fp)9{10 size_t cnt;1112 if (fp->flags&_IOREAD)13 return 0;1415 cnt = fp->wp - fp->buf;16 if (cnt > 0 && _write(fp->fd, fp->buf, cnt) != cnt) {17 fp->flags |= _IOERR;18 return EOF;19 }20 fp->wp = fp->buf;2122 return 0;23}