From: Christian Brauner Date: Sun, 15 Mar 2020 01:34:20 +0000 (+0100) Subject: memory_utils: adapt to new infrastructure X-Git-Tag: lxc-4.0.0~30^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e87cb176f72c13f97807636690cefa9a5744b03;p=thirdparty%2Flxc.git memory_utils: adapt to new infrastructure Signed-off-by: Christian Brauner --- diff --git a/src/lxc/memory_utils.h b/src/lxc/memory_utils.h index 5968eee1e..6758864fd 100644 --- a/src/lxc/memory_utils.h +++ b/src/lxc/memory_utils.h @@ -21,16 +21,37 @@ #define call_cleaner(cleaner) __attribute__((__cleanup__(cleaner##_function))) +#define close_prot_errno_disarm(fd) \ + if (fd >= 0) { \ + int _e_ = errno; \ + close(fd); \ + errno = _e_; \ + fd = -EBADF; \ + } + +static inline void close_prot_errno_disarm_function(int *fd) +{ + close_prot_errno_disarm(*fd); +} +#define __do_close_prot_errno call_cleaner(close_prot_errno_disarm) + +define_cleanup_function(FILE *, fclose); +#define __do_fclose call_cleaner(fclose) + +define_cleanup_function(DIR *, closedir); +#define __do_closedir call_cleaner(closedir) + #define free_disarm(ptr) \ ({ \ free(ptr); \ move_ptr(ptr); \ }) -static inline void __auto_free__(void *p) +static inline void free_disarm_function(void *ptr) { - free(*(void **)p); + free_disarm(*(void **)ptr); } +#define __do_free call_cleaner(free_disarm) static inline void free_string_list(char **list) { @@ -41,38 +62,7 @@ static inline void free_string_list(char **list) } } define_cleanup_function(char **, free_string_list); -#define __do_free_string_list \ - __attribute__((__cleanup__(free_string_list_function))) - -static inline void __auto_fclose__(FILE **f) -{ - if (*f) - fclose(*f); -} - -static inline void __auto_closedir__(DIR **d) -{ - if (*d) - closedir(*d); -} - -#define close_prot_errno_disarm(fd) \ - if (fd >= 0) { \ - int _e_ = errno; \ - close(fd); \ - errno = _e_; \ - fd = -EBADF; \ - } - -static inline void __auto_close__(int *fd) -{ - close_prot_errno_disarm(*fd); -} - -#define __do_close_prot_errno __attribute__((__cleanup__(__auto_close__))) -#define __do_free __attribute__((__cleanup__(__auto_free__))) -#define __do_fclose __attribute__((__cleanup__(__auto_fclose__))) -#define __do_closedir __attribute__((__cleanup__(__auto_closedir__))) +#define __do_free_string_list call_cleaner(free_string_list) static inline void *memdup(const void *data, size_t len) {