mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2025-04-19 17:37:09 +02:00
34 lines
758 B
C
34 lines
758 B
C
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include "fileutil.h"
|
|
|
|
int fflush(FILE *fp)
|
|
{
|
|
// TODO: fflush(NULL) should flush "all" files (do we track them?)
|
|
if(!fp) {
|
|
errno = EINVAL;
|
|
return EOF;
|
|
}
|
|
if(!fp->buf)
|
|
return 0;
|
|
|
|
/* In reading mode, reset the file offset */
|
|
if(fp->bufdir == __FILE_BUF_READ && fp->bufpos < fp->bufread) {
|
|
fp->fdpos = fp->fdpos - fp->bufread + fp->bufpos;
|
|
lseek(fp->fd, fp->fdpos, SEEK_SET);
|
|
fp->bufpos = 0;
|
|
fp->bufread = 0;
|
|
return 0;
|
|
}
|
|
|
|
/* In writing mode, write pending data */
|
|
if(fp->bufdir == __FILE_BUF_WRITE && fp->bufpos > 0) {
|
|
ssize_t written = __fp_write(fp, fp->buf, fp->bufpos);
|
|
int rc = (written == (ssize_t)fp->bufpos ? 0 : EOF);
|
|
fp->bufpos = 0;
|
|
return rc;
|
|
}
|
|
|
|
return 0;
|
|
}
|