summaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
index e56fe14..92ff61d 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -2,6 +2,8 @@
#ifndef __UTILS_H
#define __UTILS_H
+#include <stdint.h>
+#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
@@ -15,6 +17,28 @@ extern void *xrealloc( void *, size_t );
extern char *dupstr( char *s );
+static inline void freep(void **p)
+{
+ if (*p)
+ free(*p);
+}
+
+#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
+ static inline void func##p(type *p) \
+ { \
+ if (*p) \
+ *p = func(*p); \
+ }
+
+#define _cleanup_(_some_) __attribute__((__cleanup__(_some_)))
+#define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp)
+#define _cleanup_bus_close_unref_ _cleanup_(sd_bus_close_unrefp)
+#define _cleanup_bus_slot_unref_ _cleanup_(sd_bus_slot_unrefp)
+#define _cleanup_bus_message_unref_ _cleanup_(sd_bus_message_unrefp)
+#define _cleanup_bus_creds_unref_ _cleanup_(sd_bus_creds_unrefp)
+#define _cleanup_bus_track_unref_ _cleanup_(sd_bus_slot_unrefp)
+#define _cleanup_bus_error_free_ _cleanup_(sd_bus_error_free)
+#define _cleanup_free_ _cleanup_(freep)
#ifdef __cplusplus
}