summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-11 18:07:27 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-11 18:07:27 +0200
commite6fdfd4c4c753fe3a06edc4ae3b767c57c10d3f7 (patch)
tree9d75b0009acc15cb5ed085f968a24b221266b44e /shared
parent3dc8d84af1753b41fe37b3b3954731379dc579aa (diff)
Flesh out the new command a bit more
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