bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] fflush: avoid warnings on modern systems


From: Jim Meyering
Subject: [PATCH] fflush: avoid warnings on modern systems
Date: Mon, 26 Jan 2009 18:34:41 +0100

Hi Eric,

Building coreutils (with warnings and -Werror), I see this:

    cc1: warnings being treated as errors
    fflush.c: In function 'rpl_fflush':
    fflush.c:112: error: unused variable 'pos'
    fflush.c:111: error: unused variable 'result'

Annoyed that portability cruft is evoking warnings,
I propose to add even more cruft ;-)
What do you think?

Is it worth reindenting for the outer (pos-enclosing) braces I added?
I presume C99 decl-after-code is not an option.

Jim

>From 5bc5a63fbe7a13b538cffdb0a933a9a33bda8fd4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 26 Jan 2009 18:32:23 +0100
Subject: [PATCH] fflush: avoid warnings on modern systems

* lib/fflush.c (rpl_fflush): Move declarations of locals,
pos and result, into scopes where they're used.
---
 lib/fflush.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/fflush.c b/lib/fflush.c
index 1292a1b..6d9c34a 100644
--- a/lib/fflush.c
+++ b/lib/fflush.c
@@ -102,9 +102,6 @@ update_fpos_cache (FILE *fp, off_t pos)
 int
 rpl_fflush (FILE *stream)
 {
-  int result;
-  off_t pos;
-
   /* When stream is NULL, POSIX and C99 only require flushing of "output
      streams and update streams in which the most recent operation was not
      input", and all implementations do this.
@@ -134,6 +131,9 @@ rpl_fflush (FILE *stream)
   return fflush (stream);

 #else
+  {
+  off_t pos;
+

   /* Notes about the file-position indicator:
      1) The file position indicator is incremented by fgetc() and decremented
@@ -171,9 +171,11 @@ rpl_fflush (FILE *stream)
   /* To get here, we must be flushing a seekable input stream, so the
      semantics of fpurge are now appropriate to clear the buffer.  To
      avoid losing data, the lseek is also necessary.  */
-  result = fpurge (stream);
-  if (result != 0)
-    return result;
+  {
+    int result = fpurge (stream);
+    if (result != 0)
+      return result;
+  }

 # if (defined __sferror || defined __DragonFly__) && defined __SNPT /* 
FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */

@@ -182,8 +184,7 @@ rpl_fflush (FILE *stream)
        following fseeko call to seek to the desired position directly, rather
        than to seek to a block-aligned boundary.  */
     int saved_flags = disable_seek_optimization (stream);
-
-    result = fseeko (stream, pos, SEEK_SET);
+    int result = fseeko (stream, pos, SEEK_SET);

     restore_seek_optimization (stream, saved_flags);
   }
@@ -201,5 +202,6 @@ rpl_fflush (FILE *stream)
   return 0;

 # endif
+  }
 #endif
 }
--
1.6.1.1.347.g3f81d




reply via email to

[Prev in Thread] Current Thread [Next in Thread]