On Tue, Jul 24, 2007 at 01:44:31PM -0600, Eric Blake wrote:
> If gnulib's approach does not work on DragonFly, you are welcome to patch
> either DragonFly to comply with POSIX, or submit a patch to gnulib so that
> gnulib's approach will work on DragonFly.
Attached is a replacement version of fflush that is the least intrusive
version I can think of. No further replacements for ftello/fseeko are
needed. It should work with all BSD derived stdio implementations,
directly tested are NetBSD and DragonFly.
Joerg
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
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);
}
_______________________________________________
Bug-m4 mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-m4