usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-system-quote-child.c
blob5a83b1f3c283c0b779b20b43587f83932664c17a
1 /* Child program invoked by test-system-quote-main.
2 Copyright (C) 2012-2024 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #include <stdio.h>
20 #include <string.h>
22 /* Do not use any gnulib replacements, since this program should
23 link against as few libraries as possible. */
24 #undef fclose
25 #undef fopen
26 #undef fprintf
27 #undef fread
28 /* Restore the original fopen definition on AIX. */
29 #if defined _AIX && defined _LARGE_FILES
30 # define fopen fopen64
31 #endif
33 #define EXPECTED_DATA_FILE "t-sq-data.tmp"
35 int
36 main (int argc, char *argv[])
38 const char *arg;
39 char expected_data[1000];
40 size_t expected_data_len;
42 if (argc < 2)
43 /* Expected one data argument, received none. */
44 return 2;
45 if (argc > 2)
46 /* Expected one data argument, received more than one. */
47 return 3;
48 arg = argv[1];
50 /* Read the contents of EXPECTED_DATA_FILE. */
52 FILE *fp = fopen (EXPECTED_DATA_FILE, "rb");
53 if (fp == NULL)
54 return 4;
55 expected_data_len = fread (expected_data, 1, sizeof (expected_data), fp);
56 if (fclose (fp))
57 return 5;
60 if (!(strlen (arg) == expected_data_len
61 && memcmp (arg, expected_data, expected_data_len) == 0))
63 /* arg is not as expected. */
64 fprintf (stderr, "expected: %.*s\nreceived: %s\n",
65 (int)expected_data_len, expected_data, arg);
66 return 1;
68 else
69 return 0;