Move make_cleanup_close to common code
[deliverable/binutils-gdb.git] / gdb / common / filestuff.c
index 14d63246ca7f338b5f79134442b226b6f77db9b7..25ea8fa61b4fe81b04e1d03b8fb8387d5cb4fa4b 100644 (file)
@@ -404,3 +404,24 @@ gdb_pipe_cloexec (int filedes[2])
 
   return result;
 }
+
+/* Helper function which does the work for make_cleanup_close.  */
+
+static void
+do_close_cleanup (void *arg)
+{
+  int *fd = arg;
+
+  close (*fd);
+}
+
+/* See cleanup-utils.h.  */
+
+struct cleanup *
+make_cleanup_close (int fd)
+{
+  int *saved_fd = xmalloc (sizeof (fd));
+
+  *saved_fd = fd;
+  return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
+}
This page took 0.024332 seconds and 4 git commands to generate.