summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-16 05:25:57 +0200
committerLennart Poettering <lennart@poettering.net>2013-04-16 05:25:57 +0200
commitdfb33a9737e62ab872d3937b7690b252d2892fe8 (patch)
tree2cdc28e66d418c32c96cb2572c81cf9a3f8517bb /src/shared/util.h
parent82da66fb750c91f06e713ff23a5e5c57ff05c2a8 (diff)
macro: rework how we define cleanup macros
There's now a generic _cleanup_ macro with an argument. The macros for specific types are now defined using this macro, and in the header files where they belong. All cleanup handlers are now inline functions.
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index 683ff5a4fe..3aac165e67 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -38,7 +38,6 @@
#include <stddef.h>
#include <unistd.h>
-#include <systemd/sd-journal.h>
#include "macro.h"
#include "time-util.h"
@@ -527,19 +526,37 @@ static inline void freep(void *p) {
free(*(void**) p);
}
-void fclosep(FILE **f);
-void pclosep(FILE **f);
-void closep(int *fd);
-void closedirp(DIR **d);
-static inline void umaskp(mode_t *u) {
- umask(*u);
+static inline void fclosep(FILE **f) {
+ if (*f)
+ fclose(*f);
+}
+
+static inline void pclosep(FILE **f) {
+ if (*f)
+ pclose(*f);
+}
+
+static inline void closep(int *fd) {
+ if (*fd >= 0)
+ close_nointr_nofail(*fd);
+}
+
+static inline void closedirp(DIR **d) {
+ if (*d)
+ closedir(*d);
}
-static inline void journal_closep(sd_journal **j) {
- sd_journal_close(*j);
+static inline void umaskp(mode_t *u) {
+ umask(*u);
}
-#define _cleanup_globfree_ __attribute__((cleanup(globfree)))
+#define _cleanup_free_ _cleanup_(freep)
+#define _cleanup_fclose_ _cleanup_(fclosep)
+#define _cleanup_pclose_ _cleanup_(pclosep)
+#define _cleanup_close_ _cleanup_(closep)
+#define _cleanup_closedir_ _cleanup_(closedirp)
+#define _cleanup_umask_ _cleanup_(umaskp)
+#define _cleanup_globfree_ _cleanup_(globfree)
_malloc_ static inline void *malloc_multiply(size_t a, size_t b) {
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
@@ -608,7 +625,7 @@ int create_tmp_dir(char template[], char** dir_name);
static inline void *mempset(void *s, int c, size_t n) {
memset(s, c, n);
- return (char*)s + n;
+ return (uint8_t*)s + n;
}
char *hexmem(const void *p, size_t l);
@@ -619,7 +636,7 @@ char *strrep(const char *s, unsigned n);
void* greedy_realloc(void **p, size_t *allocated, size_t need);
#define GREEDY_REALLOC(array, allocated, need) \
- greedy_realloc((void**) &(array), &(allocated), (sizeof *array) * (need))
+ greedy_realloc((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;