]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
memory_utils: adapt to new infrastructure
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 15 Mar 2020 01:34:20 +0000 (02:34 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 15 Mar 2020 01:34:20 +0000 (02:34 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/memory_utils.h

index 5968eee1e0d53ee437e8ea4f863b575bb6491406..6758864fd69513e372847e8cf40431da1f665ab0 100644 (file)
 
 #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)
 {