chiark / gitweb /
NOT FOR UPSTREAM - CHANGELOG VERSION
[gnupg2.git] / tests / gpgscm / t-child.c
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 <https://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 main (int argc, char **argv)
32 {
33   char buffer[4096];
34   memset (buffer, 'A', sizeof buffer);
35 #if _WIN32
36   if (! setmode (stdin, O_BINARY))
37     return 23;
38   if (! setmode (stdout, O_BINARY))
39     return 23;
40 #endif
41
42   if (argc == 1)
43     return 2;
44   else if (strcmp (argv[1], "return0") == 0)
45     return 0;
46   else if (strcmp (argv[1], "return1") == 0)
47     return 1;
48   else if (strcmp (argv[1], "return77") == 0)
49     return 77;
50   else if (strcmp (argv[1], "hello_stdout") == 0)
51     fprintf (stdout, "hello");
52   else if (strcmp (argv[1], "hello_stderr") == 0)
53     fprintf (stderr, "hello");
54   else if (strcmp (argv[1], "stdout4096") == 0)
55     fwrite (buffer, 1, sizeof buffer, stdout);
56   else if (strcmp (argv[1], "stdout8192") == 0)
57     {
58       fwrite (buffer, 1, sizeof buffer, stdout);
59       fwrite (buffer, 1, sizeof buffer, stdout);
60     }
61   else if (strcmp (argv[1], "cat") == 0)
62     while (! feof (stdin))
63       {
64         size_t bytes_read;
65         bytes_read = fread (buffer, 1, sizeof buffer, stdin);
66         fwrite (buffer, 1, bytes_read, stdout);
67       }
68   else
69     {
70       fprintf (stderr, "unknown command %s\n", argv[1]);
71       return 2;
72     }
73   return 0;
74 }