summaryrefslogtreecommitdiffstats
path: root/util/cleanup.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 08:38:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 08:38:36 +0000
commit3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87 (patch)
tree2020852fabf5e530c687d41e36ddc5c453b0c9ed /util/cleanup.h
parentAdding upstream version 2.9.1. (diff)
downloadnvme-cli-3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87.tar.xz
nvme-cli-3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87.zip
Adding upstream version 2.10.upstream/2.10
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'util/cleanup.h')
-rw-r--r--util/cleanup.h33
1 files changed, 27 insertions, 6 deletions
diff --git a/util/cleanup.h b/util/cleanup.h
index ee9b120..ff26cda 100644
--- a/util/cleanup.h
+++ b/util/cleanup.h
@@ -5,6 +5,8 @@
#include <unistd.h>
#include <stdlib.h>
+#include <libnvme.h>
+
#include "util/mem.h"
#define __cleanup__(fn) __attribute__((cleanup(fn)))
@@ -21,17 +23,36 @@ DECLARE_CLEANUP_FUNC(name, type) \
static inline void freep(void *p)
{
- free(*(void**) p);
+ free(*(void **)p);
}
#define _cleanup_free_ __cleanup__(freep)
#define _cleanup_huge_ __cleanup__(nvme_free_huge)
-static inline void close_file(int *f)
+static inline void cleanup_fd(int *fd)
{
- if (*f > STDERR_FILENO)
- close(*f);
+ if (*fd > STDERR_FILENO)
+ close(*fd);
}
-#define _cleanup_file_ __cleanup__(close_file)
+#define _cleanup_fd_ __cleanup__(cleanup_fd)
+
+static inline void cleanup_nvme_root(nvme_root_t *r)
+{
+ nvme_free_tree(*r);
+}
+#define _cleanup_nvme_root_ __cleanup__(cleanup_nvme_root)
+
+static inline DEFINE_CLEANUP_FUNC(cleanup_nvme_ctrl, nvme_ctrl_t, nvme_free_ctrl)
+#define _cleanup_nvme_ctrl_ __cleanup__(cleanup_nvme_ctrl)
+
+static inline void free_uri(struct nvme_fabrics_uri **uri)
+{
+ if (*uri)
+ nvme_free_uri(*uri);
+}
+#define _cleanup_uri_ __cleanup__(free_uri)
+
+static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose)
+#define _cleanup_file_ __cleanup__(cleanup_file)
-#endif
+#endif /* __CLEANUP_H */