changeset 12452:cc0faab513a7

fflush: avoid compilation error on NetBSD On NetBSD, the system <stdio.h> header contains: |#if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC) |typedef __off_t fpos_t; |#else |typedef struct __sfpos { | __off_t _pos; |} fpos_t; |#endif Thus, based on compiler flags (such as using 'gcc -ansi' or the Intel compiler), it is an error to directly set fpos_t=off_t. * lib/fflush.c (update_fpos_cache): Use a union to safely convert between off_t and fpos_t, since the latter is sometimes a struct. * lib/fseeko.c (rpl_fseeko): Likewise. Reported by Alexander Nasonov <alnsn@yandex.ru>. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Mon, 14 Dec 2009 15:42:13 -0700
parents 419d4e1a3d41
children 41db359d31ee
files ChangeLog lib/fflush.c lib/fseeko.c
diffstat 3 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-16  Eric Blake  <ebb9@byu.net>
+
+	fflush: avoid compilation error on NetBSD
+	* lib/fflush.c (update_fpos_cache): Use a union to safely convert
+	between off_t and fpos_t, since the latter is sometimes a struct.
+	* lib/fseeko.c (rpl_fseeko): Likewise.
+	Reported by Alexander Nasonov <alnsn@yandex.ru>.
+
 2009-12-15  Eric Blake  <ebb9@byu.net>
 
 	fcntl-h, stdio, sys_ioctl: fix declarations
--- a/lib/fflush.c
+++ b/lib/fflush.c
@@ -91,7 +91,16 @@
 update_fpos_cache (FILE *fp, off_t pos)
 {
 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
-  fp_->_offset = pos;
+  /* 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;
   fp_->_flags |= __SOFF;
 #endif
 }
--- a/lib/fseeko.c
+++ b/lib/fseeko.c
@@ -110,7 +110,18 @@
 #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
       fp->_flags &= ~_IO_EOF_SEEN;
 #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
-      fp_->_offset = pos;
+      {
+        /* 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;
+      }
       fp_->_flags |= __SOFF;
       fp_->_flags &= ~__SEOF;
 #elif defined __EMX__               /* emx+gcc */