summaryrefslogtreecommitdiffstats
path: root/util/cleanup.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-24 07:57:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-24 07:57:49 +0000
commitfc67d3ad9a2903cc33e5cdaedaad51dd86a42236 (patch)
tree4ef72536a965fe220e71aea78b76b6bbbac2ed59 /util/cleanup.h
parentAdding upstream version 2.5. (diff)
downloadnvme-cli-fc67d3ad9a2903cc33e5cdaedaad51dd86a42236.tar.xz
nvme-cli-fc67d3ad9a2903cc33e5cdaedaad51dd86a42236.zip
Adding upstream version 2.7.1.upstream/2.7.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'util/cleanup.h')
-rw-r--r--util/cleanup.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/util/cleanup.h b/util/cleanup.h
index 575a25d..ee9b120 100644
--- a/util/cleanup.h
+++ b/util/cleanup.h
@@ -2,6 +2,11 @@
#ifndef __CLEANUP_H
#define __CLEANUP_H
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "util/mem.h"
+
#define __cleanup__(fn) __attribute__((cleanup(fn)))
#define DECLARE_CLEANUP_FUNC(name, type) \
@@ -14,6 +19,19 @@ DECLARE_CLEANUP_FUNC(name, type) \
free_fn(*__p); \
}
-DECLARE_CLEANUP_FUNC(cleanup_charp, char *);
+static inline void freep(void *p)
+{
+ free(*(void**) p);
+}
+#define _cleanup_free_ __cleanup__(freep)
+
+#define _cleanup_huge_ __cleanup__(nvme_free_huge)
+
+static inline void close_file(int *f)
+{
+ if (*f > STDERR_FILENO)
+ close(*f);
+}
+#define _cleanup_file_ __cleanup__(close_file)
#endif