This commit is contained in:
Robert Swiecki 2016-03-08 18:23:26 +01:00
parent e561dc6bb1
commit 833cf5d2c8
2 changed files with 10 additions and 7 deletions

View File

@ -34,13 +34,16 @@
#define _STRMERGE(a, b) a##b
#ifdef __clang__
static void __attribute__((unused)) _clang_cleanup_func(void (^*dfunc)(void)) { (*dfunc)(); }
#define defer(a) void (^_STRMERGE(__df_, __COUNTER__))(void) __attribute__((cleanup(_clang_cleanup_func))) __attribute__((unused)) = ^{ a; }
#else
#define __block
#define defer(a) void _STRMERGE(_cleanup_func_, __LINE__)(void *_STRMERGE(_cleanup_unused_, __LINE__) __attribute__((unused))) { a; } ; int _STRMERGE(_cleanup_var_, __LINE__) __attribute__((cleanup(_STRMERGE(_cleanup_func_, __LINE__)))) __attribute__((unused))
#endif
static void __attribute__ ((unused)) _clang_cleanup_func(void (^*dfunc) (void))
{
(*dfunc) ();
}
#define defer(a) void (^_STRMERGE(__df_, __COUNTER__))(void) __attribute__((cleanup(_clang_cleanup_func))) __attribute__((unused)) = ^{ a; }
#else
#define __block
#define defer(a) void _STRMERGE(_cleanup_func_, __LINE__)(void *_STRMERGE(_cleanup_unused_, __LINE__) __attribute__((unused))) { a; } ; int _STRMERGE(_cleanup_var_, __LINE__) __attribute__((cleanup(_STRMERGE(_cleanup_func_, __LINE__)))) __attribute__((unused))
#endif
struct pids_t {
pid_t pid;

2
net.c
View File

@ -327,7 +327,7 @@ static bool netIfaceUp(const char *ifacename)
PLOG_E("socket(AF_INET, SOCK_STREAM, IPPROTO_IP)");
return false;
}
defer(close(sock));
defer(close(sock));
struct ifreq ifr;
memset(&ifr, '\0', sizeof(ifr));