+++ /dev/null
-// SPDX-License-Identifier: LGPL-2.1-or-later
-#include <stdlib.h>
-#include "cleanup.h"
-
-DEFINE_CLEANUP_FUNC(cleanup_charp, char *, free);
#ifndef __CLEANUP_H
#define __CLEANUP_H
+#include <dirent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
#define __cleanup__(fn) __attribute__((cleanup(fn)))
#define DECLARE_CLEANUP_FUNC(name, type) \
free_fn(*__p); \
}
-DECLARE_CLEANUP_FUNC(cleanup_charp, char *);
+static inline void freep(void *p)
+{
+ free(*(void **)p);
+}
+#define _cleanup_free_ __cleanup__(freep)
+
+static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose)
+#define _cleanup_file_ __cleanup__(cleanup_file)
+
+static inline DEFINE_CLEANUP_FUNC(cleanup_dir, DIR *, closedir)
+#define _cleanup_dir_ __cleanup__(cleanup_dir)
+
+static inline void cleanup_fd(int *fd)
+{
+ if (*fd >= 0)
+ close(*fd);
+}
+#define _cleanup_fd_ __cleanup__(cleanup_fd)
#endif
"[%s] <%s>%s ",
"[%s] <%s> %s: ",
};
- char *header __cleanup__(cleanup_charp) = NULL;
- char *message __cleanup__(cleanup_charp) = NULL;
+ _cleanup_free_ char *header = NULL;
+ _cleanup_free_ char *message = NULL;
int idx = 0;
if (!r)