]>
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 HAVE___FPENDING
15 __fpending(FILE *stream
__attribute__((__unused__
)))
22 close_stream(FILE * stream
)
24 const int some_pending
= (__fpending(stream
) != 0);
25 const int prev_fail
= (ferror(stream
) != 0);
26 const int fclose_fail
= (fclose(stream
) != 0);
27 if (prev_fail
|| (fclose_fail
&& (some_pending
|| errno
!= EBADF
))) {
35 /* Meant to be used atexit(close_stdout); */
39 if (close_stream(stdout
) != 0 && !(errno
== EPIPE
)) {
41 warn(_("write error"));
43 warnx(_("write error"));
47 if (close_stream(stderr
) != 0)
53 fsync(int fd
__attribute__((__unused__
)))
62 const int fsync_fail
= (fsync(fd
) != 0);
63 const int close_fail
= (close(fd
) != 0);
65 if (fsync_fail
|| close_fail
)
70 #endif /* UTIL_LINUX_CLOSESTREAM_H */