summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/utils.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/shared/utils.h b/shared/utils.h
index 9404323..c47f9a5 100644
--- a/shared/utils.h
+++ b/shared/utils.h
@@ -10,6 +10,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
+#include <unistd.h>
extern unsigned debug_mask;
@@ -127,4 +128,18 @@ static inline bool strcaseeq(const char *a, const char *b)
#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d))
+#define _cleanup_(x) __attribute__((cleanup(x)))
+
+static inline void closep(int *fd)
+{
+ if (*fd && *fd >= 0)
+ close(*fd);
+}
+#define _cleanup_close_ _cleanup_(closep)
+
+static inline void freep(void *p) {
+ xfree(*(void**)p);
+}
+#define _cleanup_free_ _cleanup_(freep)
+
#endif