]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blob - tests/example.h
facbc30d5b4660170981751fb0fc92f0ffc9d52f
[coloredstderr/coloredstderr.git] / tests / example.h
1 /*
2  * Helper functions/macros for example files.
3  *
4  * Copyright (C) 2013  Simon Ruderich
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #define FORKED_TEST(pid) \
22     pid = fork(); \
23     if (pid == -1) { \
24         perror("fork"); \
25         exit(EXIT_FAILURE); \
26     } else if (pid != 0) { \
27         int status; \
28         if (waitpid(pid, &status, 0) == -1) { \
29             perror("waitpid"); \
30             exit(EXIT_FAILURE); \
31         } \
32         if (WIFEXITED(status)) { \
33             printf("exit code: %d\n", WEXITSTATUS(status)); \
34         } else { \
35             printf("child terminated!\n"); \
36         } \
37         fflush(stdout); \
38     } else