summaryrefslogtreecommitdiffstats
path: root/util/cleanup.h
diff options
context:
space:
mode:
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