]> git.proxmox.com Git - mirror_lxc.git/commitdiff
memory_utils: introduce __do_close_prot_errno
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 17 Feb 2019 13:31:52 +0000 (14:31 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 18 Feb 2019 14:24:13 +0000 (15:24 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/memory_utils.h

index d42babfd8fa735cfb08942fb9ef293098ea4cc66..fdcfb5530108e7cfe09e2a5f5a36b51ec63f61cf 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 static inline void __auto_free__(void *p)
 {
@@ -44,6 +45,16 @@ static inline void __auto_closedir__(DIR **d)
                closedir(*d);
 }
 
+static inline void __auto_close__(int *fd)
+{
+       if (*fd >= 0) {
+               int e = errno;
+               close(*fd);
+               errno = e;
+       }
+}
+
+#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__)))