fcntl-h: default O_SEARCH, O_EXEC back to O_RDONLY
[gnulib.git] / lib / fflush.c
index 3b17655..7e70727 100644 (file)
@@ -1,5 +1,5 @@
 /* fflush.c -- allow flushing input streams
-   Copyright (C) 2007-2009 Free Software Foundation, Inc.
+   Copyright (C) 2007-2012 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <unistd.h>
 
 #include "freading.h"
-#include "fpurge.h"
 
 #include "stdio-impl.h"
 
+#include "unused-parameter.h"
+
 #undef fflush
 
 
@@ -40,7 +41,7 @@ clear_ungetc_buffer_preserving_position (FILE *fp)
 {
   if (fp->_flags & _IO_IN_BACKUP)
     /* _IO_free_backup_area is a bit complicated.  Simply call fseek.  */
-    fseek (fp, 0, SEEK_CUR);
+    fseeko (fp, 0, SEEK_CUR);
 }
 
 #else
@@ -49,7 +50,7 @@ clear_ungetc_buffer_preserving_position (FILE *fp)
 static inline void
 clear_ungetc_buffer (FILE *fp)
 {
-# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
+# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
   if (HASUB (fp))
     {
       fp_->_p += fp_->_r;
@@ -61,22 +62,16 @@ clear_ungetc_buffer (FILE *fp)
       fp->_ungetc_count = 0;
       fp->_rcount = - fp->_rcount;
     }
-# elif defined _IOERR               /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
+# elif defined _IOERR               /* Minix, AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
   /* Nothing to do.  */
-# elif defined __MINT__             /* Atari FreeMiNT */
-  if (fp->__pushed_back)
-    {
-      fp->__bufp = fp->__pushback_bufp;
-      fp->__pushed_back = 0;
-    }
 # else                              /* other implementations */
-  fseek (fp, 0, SEEK_CUR);
+  fseeko (fp, 0, SEEK_CUR);
 # endif
 }
 
 #endif
 
-#if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
+#if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
 
 static inline int
 disable_seek_optimization (FILE *fp)
@@ -95,10 +90,26 @@ restore_seek_optimization (FILE *fp, int saved_flags)
 #endif
 
 static inline void
-update_fpos_cache (FILE *fp, off_t pos)
+update_fpos_cache (FILE *fp _GL_UNUSED_PARAMETER,
+                   off_t pos _GL_UNUSED_PARAMETER)
 {
-#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
+#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+# if defined __CYGWIN__
+  /* fp_->_offset is typed as an integer.  */
   fp_->_offset = pos;
+# else
+  /* fp_->_offset is an fpos_t.  */
+  /* Use a union, since on NetBSD, the compilation flags determine
+     whether fpos_t is typedef'd to off_t or a struct containing a
+     single off_t member.  */
+  union
+    {
+      fpos_t f;
+      off_t o;
+    } u;
+  u.o = pos;
+  fp_->_offset = u.f;
+# endif
   fp_->_flags |= __SOFF;
 #endif
 }
@@ -180,7 +191,7 @@ rpl_fflush (FILE *stream)
         return result;
     }
 
-# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
+# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
 
     {
       /* Disable seek optimization for the next fseeko call.  This tells the