summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2014-12-17 22:28:58 -0500
committerColin Walters <walters@verbum.org>2014-12-17 22:28:58 -0500
commitad3a28c5f2520d0688730aa83eaee815fb9a5762 (patch)
tree59011cfaa9b9f580cc824c856e1d7bfe01adc57b /src
parentf5a904e3cc16b2bd459fcbb88bc070ad238c8af3 (diff)
downloadlibgsystem-ad3a28c5f2520d0688730aa83eaee815fb9a5762.tar.gz
localalloc: Add gs_fd_close cleanup
Now that we're encouraging use of openat(), fds are a lot more prevalent.
Diffstat (limited to 'src')
-rw-r--r--src/gsystem-local-alloc.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/gsystem-local-alloc.h b/src/gsystem-local-alloc.h
index 71f444b..51b6251 100644
--- a/src/gsystem-local-alloc.h
+++ b/src/gsystem-local-alloc.h
@@ -184,6 +184,25 @@ GS_DEFINE_CLEANUP_FUNCTION0(GError*, gs_local_free_error, g_error_free)
#define gs_unref_keyfile __attribute__ ((cleanup(gs_local_keyfile_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, gs_local_keyfile_unref, g_key_file_unref)
+static inline void
+gs_cleanup_close_fdp (int *fdp)
+{
+ int fd;
+
+ g_assert (fdp);
+
+ fd = *fdp;
+ if (fd != -1)
+ (void) close (fd);
+}
+
+/**
+ * gs_fd_close:
+ *
+ * Call close() on a variable location when it goes out of scope.
+ */
+#define gs_fd_close __attribute__((cleanup(gs_cleanup_close_fdp)))
+
G_END_DECLS
#endif