summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-12 20:28:21 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-13 17:56:55 -0400
commit1ca208fb4f93e5869704af1812cbff7130a2fc03 (patch)
tree689343b99c76e4d34c625197762de97e8435571d /src/shared/util.h
parentb506291ff195e03ce793ac925cc2d158f0b452b5 (diff)
Introduce udev object cleanup functions
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index 09e556d011..99a138cd8e 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -556,42 +556,33 @@ static inline void freep(void *p) {
free(*(void**) p);
}
-static inline void fclosep(FILE **f) {
- if (*f)
- fclose(*f);
-}
-
-static inline void pclosep(FILE **f) {
- if (*f)
- pclose(*f);
-}
+#define define_trivial_cleanup_func(type, func) \
+ static inline void func##p(type *p) { \
+ if (*p) \
+ func(*p); \
+ } \
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 umaskp(mode_t *u) {
umask(*u);
}
-static inline void endmntentp(FILE **f) {
- if (*f)
- endmntent(*f);
-}
+define_trivial_cleanup_func(FILE*, fclose)
+define_trivial_cleanup_func(FILE*, pclose)
+define_trivial_cleanup_func(DIR*, closedir)
+define_trivial_cleanup_func(FILE*, endmntent)
#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)
+#define _cleanup_fclose_ _cleanup_(fclosep)
+#define _cleanup_pclose_ _cleanup_(pclosep)
+#define _cleanup_closedir_ _cleanup_(closedirp)
#define _cleanup_endmntent_ _cleanup_(endmntentp)
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {