From ace67a47ede7b58fb3c8d17d5e8dfca28c35781d Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 12 Apr 2007 11:59:14 +0000 Subject: [PATCH] No need to preserve errno on success. * lib/fflush.c (rpl_fflush): Simplify errno tracking. Reported by Bruno Haible. --- ChangeLog | 6 ++++++ lib/fflush.c | 18 +++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c3ac17a65..e166d10f08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-04-12 Eric Blake + + No need to preserve errno on success. + * lib/fflush.c (rpl_fflush): Simplify errno tracking. + Reported by Bruno Haible. + 2007-04-12 Simon Josefsson * gnulib-tool (func_modules_add_dummy): Respect --avoid=dummy. diff --git a/lib/fflush.c b/lib/fflush.c index c4c575f949..5271e17dfa 100755 --- a/lib/fflush.c +++ b/lib/fflush.c @@ -36,38 +36,33 @@ int fpurge (FILE *); int rpl_fflush (FILE *stream) { - int e1; /* Leave errno unchanged on success. */ - int e2; /* Capture errno of first fflush if nothing else succeeds. */ + int e; /* Capture errno of first fflush if nothing else succeeds. */ int result; /* Try flushing the stream. C89 guarantees behavior of output streams, so we only need to worry if failure might have been on an input stream. When stream is NULL, POSIX only requires flushing of output streams. */ - e1 = errno; result = fflush (stream); - if (! stream || result == 0 || errno != EBADF) + if (! stream || result == 0 || (e = errno) != EBADF) return result; /* POSIX does not specify behavior for non-seekable streams. */ - e2 = errno; if (fseeko (stream, 0, SEEK_CUR) != 0) { - errno = e2; + errno = e; return EOF; } /* To get here, we must be flushing a seekable input stream, so the semantics of fpurge are now appropriate. */ #if HAVE_FPURGE - errno = e1; result = fpurge (stream); #elif HAVE___FPURGE /* __fpurge has no return value, and on Solaris, we can't even trust errno. So assume it succeeds. */ __fpurge (stream); result = 0; - errno = e1; #else /* ! HAVE___FPURGE */ /* No single replacement; do it manually. */ @@ -82,13 +77,10 @@ rpl_fflush (FILE *stream) else if (fseeko (stream, position, SEEK_SET) != 0) { result = EOF; - errno = e2; + errno = e; } else - { - result = 0; - errno = e1; - } + result = 0; } #endif /* ! HAVE___FPURGE */ -- 2.30.2