Use a slightly cleaner hack on BSD systems.
authorBruno Haible <bruno@clisp.org>
Tue, 31 Jul 2007 22:15:00 +0000 (22:15 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 31 Jul 2007 22:15:00 +0000 (22:15 +0000)
ChangeLog
lib/fflush.c

index cd0c69e..d4c894b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-07-31  Bruno Haible  <bruno@clisp.org>
+
+       * lib/fflush.c (rpl_fflush): On BSD systems, use the __SNPT flag.
+       Suggested by Joerg Sonnenberger <joerg@britannica.bec.de>.
+
 2007-07-30  Bruno Haible  <bruno@clisp.org>
 
        * modules/base64 (License): Use the synonymous term "LGPLv2+".
index 459a710..cae5a5c 100755 (executable)
@@ -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
 }