fshut.h - blind - suckless command-line video editing utility
 (HTM) git clone git://git.suckless.org/blind
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       fshut.h (798B)
       ---
            1 /* See LICENSE file for copyright and license details. */
            2 #include <stdio.h>
            3 
            4 #define efshut(...) enfshut(1, __VA_ARGS__)
            5 
            6 static inline int
            7 fshut(FILE *fp, const char *fname)
            8 {
            9         int ret = 0;
           10 
           11         /* fflush() is undefined for input streams by ISO C,
           12          * but not POSIX 2008 if you ignore ISO C overrides.
           13          * Leave it unchecked and rely on the following
           14          * functions to detect errors.
           15          */
           16         fflush(fp);
           17 
           18         if (ferror(fp) && !ret) {
           19                 weprintf("ferror %s:", fname);
           20                 ret = 1;
           21         }
           22 
           23         if (fclose(fp) && !ret) {
           24                 weprintf("fclose %s:", fname);
           25                 ret = 1;
           26         }
           27 
           28         return ret;
           29 }
           30 
           31 static inline void
           32 enfshut(int status, FILE *fp, const char *fname)
           33 {
           34          if (fshut(fp, fname))
           35                 exit(status);
           36 }