From 9faed5de047d34fddbd4cddbfee73d1fbcea5e32 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 31 Jul 2007 22:15:00 +0000 Subject: [PATCH] Use a slightly cleaner hack on BSD systems. --- ChangeLog | 5 +++++ lib/fflush.c | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd0c69e56..d4c894b21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-07-31 Bruno Haible + + * lib/fflush.c (rpl_fflush): On BSD systems, use the __SNPT flag. + Suggested by Joerg Sonnenberger . + 2007-07-30 Bruno Haible * modules/base64 (License): Use the synonymous term "LGPLv2+". diff --git a/lib/fflush.c b/lib/fflush.c index 459a71070..cae5a5c16 100755 --- a/lib/fflush.c +++ b/lib/fflush.c @@ -77,15 +77,34 @@ rpl_fflush (FILE *stream) if (result != 0) return result; +#if defined __sferror && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ + + { + /* Disable seek optimization for the next fseeko call. This tells the + following fseeko call to seek to the desired position directly, rather + than to seek to a block-aligned boundary. */ + int saved_flags = stream->_flags & (__SOPT | __SNPT); + stream->_flags = (stream->_flags & ~__SOPT) | __SNPT; + + result = fseeko (stream, pos, SEEK_SET); + + stream->_flags = (stream->_flags & ~(__SOPT | __SNPT)) | saved_flags; + } + return result; + +#else + pos = lseek (fileno (stream), pos, SEEK_SET); if (pos == -1) return EOF; /* After a successful lseek, update the file descriptor's position cache in the stream. */ -#if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ +# if defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ stream->_offset = pos; stream->_flags |= __SOFF; -#endif +# endif return 0; + +#endif } -- 2.11.0