#include #include #include int rpl_fflush(FILE *fp) { #if defined(__DragonFly__) struct __FILE_public *fp_ = (struct __FILE_public *)fp; #else #define fp_ fp #endif off_t pos; /* NULL pointer or writeable stream: use normal fflush. */ if (fp == NULL || (fp_->_flags & (__SWR | __SRW)) != 0) return fflush(fp); /* Get current position, possibly different from file pointer. */ pos = ftello(fp); if (pos == -1) { errno = EBADF; return -1; } /* Purge buffers. */ if (fpurge(fp) == EOF) return -1; /* * Disable seek optimisation. This is forces the following * fseeko to seek the actual position and not realign * the file pointer on a block boundary. */ fp_->_flags |= __SNPT; return fseeko(fp, pos, SEEK_SET); }