* clean-temp.h (close_stream_temp): New declaration.
authorEric Blake <ebb9@byu.net>
Fri, 6 Oct 2006 23:13:53 +0000 (23:13 +0000)
committerEric Blake <ebb9@byu.net>
Fri, 6 Oct 2006 23:13:53 +0000 (23:13 +0000)
* clean-temp.c (includes): Pull in headers according to what
other modules are in use.
(close_stream_temp) [GNULIB_CLOSE_STREAM]: New function.

lib/ChangeLog
lib/clean-temp.c
lib/clean-temp.h

index b947fe9..9a955ad 100644 (file)
@@ -1,3 +1,10 @@
+2006-10-06  Eric Blake  <ebb9@byu.net>
+
+       * clean-temp.h (close_stream_temp): New declaration.
+       * clean-temp.c (includes): Pull in headers according to what
+       other modules are in use.
+       (close_stream_temp) [GNULIB_CLOSE_STREAM]: New function.
+
 2006-10-06  Bruno Haible  <bruno@clisp.org>
 
        * clean-temp.h (cleanup_temp_file, cleanup_temp_subdir,
index 29a27ba..7347aaf 100644 (file)
@@ -23,6 +23,7 @@
 #include "clean-temp.h"
 
 #include <errno.h>
+#include <fcntl.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #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)
 
@@ -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
index 2503008..7edb944 100644 (file)
@@ -122,6 +122,10 @@ extern int fclose_temp (FILE *fp);
    Unregisters the previously registered file descriptor.  */
 extern int fwriteerror_temp (FILE *fp);
 
+/* Like close_stream.
+   Unregisters the previously registered file descriptor.  */
+extern int close_stream_temp (FILE *fp);
+
 
 #ifdef __cplusplus
 }