]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/closestream.h
1 #ifndef UTIL_LINUX_CLOSESTREAM_H
2 #define UTIL_LINUX_CLOSESTREAM_H
5 #ifdef HAVE_STDIO_EXT_H
13 #ifndef CLOSE_EXIT_CODE
14 # define CLOSE_EXIT_CODE EXIT_FAILURE
18 close_stream(FILE * stream
)
20 #ifdef HAVE___FPENDING
21 const int some_pending
= (__fpending(stream
) != 0);
23 const int prev_fail
= (ferror(stream
) != 0);
24 const int fclose_fail
= (fclose(stream
) != 0);
26 if (prev_fail
|| (fclose_fail
&& (
27 #ifdef HAVE___FPENDING
31 if (!fclose_fail
&& !(errno
== EPIPE
))
38 /* Meant to be used atexit(close_stdout); */
42 if (close_stream(stdout
) != 0 && !(errno
== EPIPE
)) {
44 warn(_("write error"));
46 warnx(_("write error"));
47 _exit(CLOSE_EXIT_CODE
);
50 if (close_stream(stderr
) != 0)
51 _exit(CLOSE_EXIT_CODE
);
56 fsync(int fd
__attribute__((__unused__
)))
65 const int fsync_fail
= (fsync(fd
) != 0);
66 const int close_fail
= (close(fd
) != 0);
68 if (fsync_fail
|| close_fail
)
73 #endif /* UTIL_LINUX_CLOSESTREAM_H */