From 7552ed51f78ca1ad311228f76e90cf8c120ee2f6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 4 Oct 2023 14:52:51 +0200 Subject: Adding upstream version 2.6. Signed-off-by: Daniel Baumann --- util/cleanup.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'util/cleanup.h') 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 +#include + #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 -- cgit v1.2.3