17e8cb518SIngo Weinhold /* 2*24df6592SIngo Weinhold * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@gmx.de. 37e8cb518SIngo Weinhold * Distributed under the terms of the MIT License. 47e8cb518SIngo Weinhold */ 57e8cb518SIngo Weinhold #ifndef _SYSCALL_UTILS_H 67e8cb518SIngo Weinhold #define _SYSCALL_UTILS_H 77e8cb518SIngo Weinhold 8*24df6592SIngo Weinhold 97e8cb518SIngo Weinhold #define RETURN_AND_SET_ERRNO(err) \ 107e8cb518SIngo Weinhold do { \ 11*24df6592SIngo Weinhold __typeof(err) __result = (err); \ 12*24df6592SIngo Weinhold if (__result < 0) { \ 13*24df6592SIngo Weinhold errno = __result; \ 147e8cb518SIngo Weinhold return -1; \ 157e8cb518SIngo Weinhold } \ 16*24df6592SIngo Weinhold return __result; \ 17*24df6592SIngo Weinhold } while (0) 18*24df6592SIngo Weinhold 19*24df6592SIngo Weinhold #define RETURN_AND_TEST_CANCEL(err) \ 20*24df6592SIngo Weinhold do { \ 21*24df6592SIngo Weinhold __typeof(err) __result = (err); \ 22*24df6592SIngo Weinhold pthread_testcancel(); \ 23*24df6592SIngo Weinhold return __result; \ 24*24df6592SIngo Weinhold } while (0) 25*24df6592SIngo Weinhold 26*24df6592SIngo Weinhold #define RETURN_AND_SET_ERRNO_TEST_CANCEL(err) \ 27*24df6592SIngo Weinhold do { \ 28*24df6592SIngo Weinhold __typeof(err) __result = (err); \ 29*24df6592SIngo Weinhold pthread_testcancel(); \ 30*24df6592SIngo Weinhold if (__result < 0) { \ 31*24df6592SIngo Weinhold errno = __result; \ 32*24df6592SIngo Weinhold return -1; \ 33*24df6592SIngo Weinhold } \ 34*24df6592SIngo Weinhold return __result; \ 35*24df6592SIngo Weinhold } while (0) 36*24df6592SIngo Weinhold 377e8cb518SIngo Weinhold 387e8cb518SIngo Weinhold #endif // _SYSCALL_UTILS_H 39