summaryrefslogtreecommitdiffstats
path: root/src/nvme/cleanup.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-24 07:51:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-24 07:51:48 +0000
commit8d843cc9cc0e989d3929f204f77223cd08730c7a (patch)
tree1fcba17d10325d9d7ccb68b2eb48cd9bbba6a534 /src/nvme/cleanup.h
parentReleasing debian version 1.5-3. (diff)
downloadlibnvme-8d843cc9cc0e989d3929f204f77223cd08730c7a.tar.xz
libnvme-8d843cc9cc0e989d3929f204f77223cd08730c7a.zip
Merging upstream version 1.7.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/nvme/cleanup.h')
-rw-r--r--src/nvme/cleanup.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/nvme/cleanup.h b/src/nvme/cleanup.h
index b7e1533..4327600 100644
--- a/src/nvme/cleanup.h
+++ b/src/nvme/cleanup.h
@@ -2,6 +2,11 @@
#ifndef __CLEANUP_H
#define __CLEANUP_H
+#include <dirent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
#define __cleanup__(fn) __attribute__((cleanup(fn)))
#define DECLARE_CLEANUP_FUNC(name, type) \
@@ -14,6 +19,23 @@ 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)
+
+static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose)
+#define _cleanup_file_ __cleanup__(cleanup_file)
+
+static inline DEFINE_CLEANUP_FUNC(cleanup_dir, DIR *, closedir)
+#define _cleanup_dir_ __cleanup__(cleanup_dir)
+
+static inline void cleanup_fd(int *fd)
+{
+ if (*fd >= 0)
+ close(*fd);
+}
+#define _cleanup_fd_ __cleanup__(cleanup_fd)
#endif