1/*
2 * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _SYSCALL_UTILS_H
6#define _SYSCALL_UTILS_H
7
8
9#define RETURN_AND_SET_ERRNO(err)			\
10	do {									\
11		__typeof(err) __result = (err);		\
12		if (__result < 0) {					\
13			errno = __result;				\
14			return -1;						\
15		}									\
16		return __result;					\
17	} while (0)
18
19#define RETURN_AND_TEST_CANCEL(err)			\
20	do {									\
21		__typeof(err) __result = (err);		\
22		pthread_testcancel();				\
23		return __result;					\
24	} while (0)
25
26#define RETURN_AND_SET_ERRNO_TEST_CANCEL(err)	\
27	do {										\
28		__typeof(err) __result = (err);			\
29		pthread_testcancel();					\
30		if (__result < 0) {						\
31			errno = __result;					\
32			return -1;							\
33		}										\
34		return __result;						\
35	} while (0)
36
37
38#endif	// _SYSCALL_UTILS_H
39