[hackers] [sbase] Remove fflush-check from fshut() || FRIGN

From: <git_AT_suckless.org>
Date: Sun, 5 Apr 2015 10:14:04 +0200 (CEST)

commit 0c470f5563c3d5d769dcffaae432e2df78fcc79e
Author: FRIGN <dev_AT_frign.de>
Date: Sun Apr 5 00:04:58 2015 +0200

    Remove fflush-check from fshut()
    
    Basically, it's a conflict between POSIX and ISO C what do to when
    input streams are passed to fflush().
    POSIX mandates that the seeking-position should be synced, but ISO C
    says it's undefined behaviour.
    We love POSIX, but the standard-documents specify that in all conflict
    cases, ISO C wins, so this breaks with EBADF on BSD's.
    
    musl and glibc follow POSIX behaviour, which makes sense, but involves
    numerous portability concerns.
    
    To get around this, we just don't check fflush() and rely on the fact
    that no implementation sets ferror on the file-stream in fflush if it
    is an input stream, so every issue caught in fflush() is caught later
    with ferror() and fclose().
    
    Add a comment to fshut() because this stuff is so complicated, it
    took us a day to figure out.

diff --git a/libutil/fshut.c b/libutil/fshut.c
index f243a82..4de6596 100644
--- a/libutil/fshut.c
+++ b/libutil/fshut.c
_AT_@ -7,10 +7,12 @@ int fshut(FILE *fp, const char *fname)
 {
         int ret = 0;
 
- if (fflush(fp) && !ret) {
- weprintf("fflush %s:", fname);
- ret = 1;
- }
+ /* fflush() is undefined for input streams by ISO C,
+ * but not POSIX 2008 if you ignore ISO C overrides.
+ * Leave it unchecked an rely on the following
+ * functions to detect errors.
+ */
+ fflush(fp);
 
         if (ferror(fp) && !ret) {
                 weprintf("ferror %s:", fname);
Received on Sun Apr 05 2015 - 10:14:04 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 05 2015 - 10:24:14 CEST