From 6faaf1fd6548cff28cbb5b04234d63b5ee739048 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 19 Nov 2014 18:29:24 -0500 Subject: [PATCH] cleanup: Add a _cleanup_close_ Matching systemd. --- src/rpmostree-cleanup.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/rpmostree-cleanup.h b/src/rpmostree-cleanup.h index c4cd17ad..cbdd13a4 100644 --- a/src/rpmostree-cleanup.h +++ b/src/rpmostree-cleanup.h @@ -44,6 +44,19 @@ GS_DEFINE_CLEANUP_FUNCTION0(HyQuery, _cleanup_hy_query_free, hy_query_free); GS_DEFINE_CLEANUP_FUNCTION0(HyPackageList, _cleanup_hy_packagelist_free, hy_packagelist_free); GS_DEFINE_CLEANUP_FUNCTION0(HyStringArray, _cleanup_hy_stringarray_free, hy_stringarray_free); +static inline void +cleanup_closep (int *fdp) +{ + int fd; + + g_assert (fdp); + + fd = *fdp; + if (fd != -1) + (void) close (fd); +} + +#define _cleanup_close_ __attribute__((cleanup(cleanup_closep))) #define _cleanup_hysack_ __attribute__((cleanup(_cleanup_hy_sack_free))) #define _cleanup_hyquery_ __attribute__((cleanup(_cleanup_hy_query_free))) #define _cleanup_hypackagelist_ __attribute__((cleanup(_cleanup_hy_packagelist_free)))