summaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/utils.h b/src/utils.h
index e56fe14..32d8b4b 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" {
@@ -9,12 +11,33 @@ extern "C" {
#define MAX_ERROR_MSG_SIZE PATH_MAX
-
extern void *xmalloc( size_t );
extern void *xrealloc( void *, size_t );
extern char *dupstr( char *s );
+static inline void freep(void **p)
+{
+ if (*p)
+ free(*p);
+}
+
+static inline void string_freep(char **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_free_ _cleanup_(freep)
+#define _cleanup_string_ _cleanup_(string_freep)
#ifdef __cplusplus
}