From 4215bcc7e5202438ec9d981d1753bd442871e05a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 14 Dec 2009 15:42:13 -0700 Subject: [PATCH] fflush: avoid compilation error on NetBSD On NetBSD, the system 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 . Signed-off-by: Eric Blake --- ChangeLog | 8 ++++++++ lib/fflush.c | 11 ++++++++++- lib/fseeko.c | 13 ++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index efa426c3bc..fe1b6f8edc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-12-16 Eric Blake + + 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 . + 2009-12-15 Eric Blake fcntl-h, stdio, sys_ioctl: fix declarations diff --git a/lib/fflush.c b/lib/fflush.c index 0af17034e4..d823a342c3 100644 --- a/lib/fflush.c +++ b/lib/fflush.c @@ -91,7 +91,16 @@ static inline void 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 } diff --git a/lib/fseeko.c b/lib/fseeko.c index 8887f2469d..91b853d3ab 100644 --- a/lib/fseeko.c +++ b/lib/fseeko.c @@ -110,7 +110,18 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) #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 */ -- 2.30.2