summaryrefslogtreecommitdiffstats
path: root/util/cleanup.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-04 12:52:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-04 12:52:51 +0000
commit7552ed51f78ca1ad311228f76e90cf8c120ee2f6 (patch)
treedec5ce8e28f081567cb33c77a178bcac6dd76169 /util/cleanup.h
parentAdding upstream version 2.5. (diff)
downloadnvme-cli-upstream/2.6.tar.xz
nvme-cli-upstream/2.6.zip
Adding upstream version 2.6.upstream/2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--util/cleanup.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/util/cleanup.h b/util/cleanup.h
index 575a25d..9227856 100644
--- a/util/cleanup.h
+++ b/util/cleanup.h
@@ -2,6 +2,9 @@
#ifndef __CLEANUP_H
#define __CLEANUP_H
+#include <unistd.h>
+#include <stdlib.h>
+
#define __cleanup__(fn) __attribute__((cleanup(fn)))
#define DECLARE_CLEANUP_FUNC(name, type) \
@@ -16,4 +19,17 @@ DECLARE_CLEANUP_FUNC(name, type) \
DECLARE_CLEANUP_FUNC(cleanup_charp, char *);
+static inline void freep(void *p)
+{
+ free(*(void**) p);
+}
+#define _cleanup_free_ __cleanup__(freep)
+
+static inline void close_file(int *f)
+{
+ if (*f >= 0)
+ close(*f);
+}
+#define _cleanup_file_ __cleanup__(close_file)
+
#endif