X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fclean-temp.c;h=36a529422025e2cc2594d1b154c783f0a88bfd09;hb=a0a86efb418fd595d9154cf6ca70c78ea777afb9;hp=29a27ba2138442f23806b6f11619c83e7f3831d2;hpb=05477f4de600d5e9247707024d162924d73c1a4b;p=gnulib.git diff --git a/lib/clean-temp.c b/lib/clean-temp.c index 29a27ba21..36a529422 100644 --- a/lib/clean-temp.c +++ b/lib/clean-temp.c @@ -23,6 +23,7 @@ #include "clean-temp.h" #include +#include #include #include #include @@ -38,6 +39,15 @@ #include "xallocsa.h" #include "gl_linkedhash_list.h" #include "gettext.h" +#if GNULIB_CLOSE_STREAM +# include "close-stream.h" +#endif +#if GNULIB_FCNTL_SAFER +# include "fcntl--.h" +#endif +#if GNULIB_FOPEN_SAFER +# include "stdio--.h" +#endif #define _(str) gettext (str) @@ -579,7 +589,7 @@ open_temp (const char *file_name, int flags, mode_t mode) int saved_errno; block_fatal_signals (); - fd = open (file_name, flags, mode); + fd = open (file_name, flags, mode); /* actually open or open_safer */ saved_errno = errno; if (fd >= 0) register_fd (fd); @@ -597,7 +607,7 @@ fopen_temp (const char *file_name, const char *mode) int saved_errno; block_fatal_signals (); - fp = fopen (file_name, mode); + fp = fopen (file_name, mode); /* actually fopen or fopen_safer */ saved_errno = errno; if (fp != NULL) { @@ -679,3 +689,25 @@ fwriteerror_temp (FILE *fp) return result; } #endif + +#if GNULIB_CLOSE_STREAM +/* Like close_stream. + Unregisters the previously registered file descriptor. */ +int +close_stream_temp (FILE *fp) +{ + int fd = fileno (fp); + /* No blocking of signals is needed here, since a double close of a + file descriptor is harmless. */ + int result = close_stream (fp); + int saved_errno = errno; + + /* No race condition here: we assume a single-threaded program, hence + fd cannot be re-opened here. */ + + unregister_fd (fd); + + errno = saved_errno; + return result; +} +#endif