changeset 9134:38df3bd8e54e

Use a slightly cleaner hack on BSD systems.
author Bruno Haible <bruno@clisp.org>
date Tue, 31 Jul 2007 22:15:00 +0000
parents 715de16f68a7
children 5a648774d6a3
files ChangeLog lib/fflush.c
diffstat 2 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jul 31 17:08:37 2007 +0000
+++ b/ChangeLog	Tue Jul 31 22:15:00 2007 +0000
@@ -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+".
--- a/lib/fflush.c	Tue Jul 31 17:08:37 2007 +0000
+++ b/lib/fflush.c	Tue Jul 31 22:15:00 2007 +0000
@@ -77,15 +77,34 @@
   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
 }