1/*
2 * Copyright (c) 2016 Linux Test Project
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License
13 * alone with this program.
14 */
15
16#ifndef __SAFE_HELPERS_H__
17#define __SAFE_HELPERS_H__
18
19#include <stdio.h>
20#include <string.h>
21
22#define SAFE_PFUNC(op) \
23do {\
24	int ret = (op); \
25	if (ret != 0) { \
26		printf("Test %s unresolved: got %i (%s) on line %i\n  %s\n", \
27			__FILE__, ret, strerror(ret), __LINE__, #op); \
28		fflush(stdout); \
29		exit(PTS_UNRESOLVED); \
30	} \
31} while (0)
32
33#define SAFE_FUNC(op) \
34({ \
35	int ret = (op); \
36	if (ret == -1) { \
37		printf("Test %s unresolved: got %i (%s) on line %i\n  %s\n", \
38			__FILE__, ret, strerror(errno), __LINE__, #op); \
39		fflush(stdout); \
40		exit(PTS_UNRESOLVED); \
41	} \
42	ret; \
43})
44
45#endif
46