aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/filestuff.c21
-rw-r--r--gdb/common/filestuff.h4
2 files changed, 25 insertions, 0 deletions
diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index 14d6324..25ea8fa 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -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);
+}
diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h
index 98522a6..e997ecc 100644
--- a/gdb/common/filestuff.h
+++ b/gdb/common/filestuff.h
@@ -67,4 +67,8 @@ extern int gdb_socket_cloexec (int domain, int style, int protocol);
extern int gdb_pipe_cloexec (int filedes[2]);
+/* Return a new cleanup that closes FD. */
+
+extern struct cleanup *make_cleanup_close (int fd);
+
#endif /* FILESTUFF_H */