Line data Source code
1 : /* Sanity check for the process and IPC primitives.
2 : *
3 : * Copyright (C) 2016 g10 code GmbH
4 : *
5 : * This file is part of GnuPG.
6 : *
7 : * GnuPG is free software; you can redistribute it and/or modify
8 : * it under the terms of the GNU General Public License as published by
9 : * the Free Software Foundation; either version 3 of the License, or
10 : * (at your option) any later version.
11 : *
12 : * GnuPG is distributed in the hope that it will be useful,
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : * GNU General Public License for more details.
16 : *
17 : * You should have received a copy of the GNU General Public License
18 : * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include <errno.h>
22 : #include <stdio.h>
23 : #include <string.h>
24 :
25 : #ifdef _WIN32
26 : # include <fcntl.h>
27 : # include <io.h>
28 : #endif
29 :
30 : int
31 18 : main (int argc, char **argv)
32 : {
33 : #if _WIN32
34 : if (! setmode (stdin, O_BINARY))
35 : return 23;
36 : if (! setmode (stdout, O_BINARY))
37 : return 23;
38 : #endif
39 :
40 18 : if (argc == 1)
41 0 : return 2;
42 18 : else if (strcmp (argv[1], "return0") == 0)
43 6 : return 0;
44 12 : else if (strcmp (argv[1], "return1") == 0)
45 4 : return 1;
46 8 : else if (strcmp (argv[1], "return77") == 0)
47 3 : return 77;
48 5 : else if (strcmp (argv[1], "hello_stdout") == 0)
49 2 : fprintf (stdout, "hello");
50 3 : else if (strcmp (argv[1], "hello_stderr") == 0)
51 1 : fprintf (stderr, "hello");
52 2 : else if (strcmp (argv[1], "cat") == 0)
53 6 : while (! feof (stdin))
54 : {
55 : char buffer[4096];
56 : size_t bytes_read;
57 2 : bytes_read = fread (buffer, 1, sizeof buffer, stdin);
58 2 : fwrite (buffer, 1, bytes_read, stdout);
59 : }
60 : else
61 : {
62 0 : fprintf (stderr, "unknown command %s\n", argv[1]);
63 0 : return 2;
64 : }
65 5 : return 0;
66 : }
|