summaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/utils.h b/utils.h
index 33cff05..9cb775b 100644
--- a/utils.h
+++ b/utils.h
@@ -1,6 +1,8 @@
#ifndef fooutilshfoo
#define fooutilshfoo
+#include <sys/types.h>
+#include <dirent.h>
#include <systemd/sd-bus.h>
struct list_head {
@@ -80,6 +82,17 @@ static inline void sd_bus_close_unrefp(sd_bus **bus) {
}
#define _cleanup_bus_close_unref_ _cleanup_(sd_bus_close_unrefp)
+static inline unsigned
+strv_length(char **strv)
+{
+ unsigned len;
+
+ for (len = 0; strv && *strv; strv++)
+ len++;
+
+ return len;
+}
+
static inline void strv_free(char **l) {
char **k;
if (l) {
@@ -91,9 +104,20 @@ static inline void strv_free(char **l) {
DEFINE_TRIVIAL_CLEANUP_FUNC(char **, strv_free);
#define _cleanup_strv_free_ _cleanup_(strv_freep)
-DEFINE_TRIVIAL_CLEANUP_FUNC(void *, free);
+static inline void freep(void *p) {
+ free(*(void**) p);
+}
#define _cleanup_free_ _cleanup_(freep)
+DEFINE_TRIVIAL_CLEANUP_FUNC(int, close);
+#define _cleanup_close_ _cleanup_(closep)
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(FILE *, fclose);
+#define _cleanup_fclose_ _cleanup_(fclosep)
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(DIR *, closedir);
+#define _cleanup_closedir_ _cleanup_(closedirp)
+
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus *, sd_bus_unref);
#define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp)