aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

fshut.c (738B)


      1 /* see LICENSE file for copyright and license details */
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 #include "../util.h"
      6 
      7 int
      8 fshut(FILE *fp, const char *fname)
      9 {
     10   int ret = 0;
     11 
     12   /* fflush() is undefined for input streams by ISO c,
     13    * but not POSIX 2008 if you ignore ISO c overrides
     14    * leave it unchecked and rely on the following
     15    * functions to detect errors
     16    */
     17   fflush(fp);
     18 
     19   if (ferror(fp) && !ret) {
     20     weprintf("ferror %s:", fname);
     21     ret = 1;
     22   }
     23 
     24   if (fclose(fp) && !ret) {
     25     weprintf("fclose %s:", fname);
     26     ret = 1;
     27   }
     28 
     29   return ret;
     30 }
     31 
     32 void
     33 enfshut(int status, FILE *fp, const char *fname)
     34 {
     35   if (fshut(fp, fname))
     36     exit(status);
     37 }
     38 
     39 void
     40 efshut(FILE *fp, const char *fname)
     41 {
     42   enfshut(1, fp, fname);
     43 }