usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-yesno.c
blobacb60614d7d23d9bcfad6dcbce058b9990820e7d
1 /* Test of yesno module.
2 Copyright (C) 2007-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/>.
18 #include <config.h>
20 /* Specification. */
21 #include "yesno.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
27 #include "closein.h"
28 #include "binary-io.h"
30 /* Test yesno. Without arguments, read one line. If first argument
31 is zero, close stdin before attempting to read one line.
32 Otherwise, read the number of lines specified by first
33 argument. */
34 int
35 main (int argc, char **argv)
37 int i = 1;
39 /* yesno recommends that all clients use close_stdin in main. */
40 atexit (close_stdin);
41 /* But on mingw, close_stdin leaves stdin's file descriptor at the expected
42 position (i.e. where this program left off reading) only if its mode has
43 been set to O_BINARY. If it has been set to O_TEXT, and the file
44 descriptor is seekable, and stdin is buffered, the MSVCRT runtime ends up
45 setting the file descriptor's position to the expected position _minus_
46 the number of LFs not preceded by CR that were read between the expected
47 position and the last filled buffer end position. (I.e. the repositioning
48 from the end-of-buffer to the expected position does not work if the input
49 file contains end-of-line markers in Unix convention.) */
50 set_binary_mode (0, O_BINARY);
52 if (1 < argc)
53 i = atoi (argv[1]);
54 if (!i)
56 i = 1;
57 close (0);
59 while (i--)
60 puts (yesno () ? "Y" : "N");
61 return 0;