diff options
Diffstat (limited to '')
-rw-r--r-- | util/cleanup.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/util/cleanup.h b/util/cleanup.h index 575a25d..9227856 100644 --- a/util/cleanup.h +++ b/util/cleanup.h @@ -2,6 +2,9 @@ #ifndef __CLEANUP_H #define __CLEANUP_H +#include <unistd.h> +#include <stdlib.h> + #define __cleanup__(fn) __attribute__((cleanup(fn))) #define DECLARE_CLEANUP_FUNC(name, type) \ @@ -16,4 +19,17 @@ DECLARE_CLEANUP_FUNC(name, type) \ DECLARE_CLEANUP_FUNC(cleanup_charp, char *); +static inline void freep(void *p) +{ + free(*(void**) p); +} +#define _cleanup_free_ __cleanup__(freep) + +static inline void close_file(int *f) +{ + if (*f >= 0) + close(*f); +} +#define _cleanup_file_ __cleanup__(close_file) + #endif |