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