Mercurial > gnulib
annotate tests/test-freopen.c @ 40231:9b3c79fdfe0b
strtod: fix clash with strtold
Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817).
* lib/strtod.c (compute_minus_zero, minus_zero):
Simplify by remving the macro / external variable,
and having just a function. User changed. This avoids
the need for an external variable that might clash.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Mar 2019 16:40:29 -0700 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
9303 | 1 /* Test of opening a file stream. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2007-2019 Free Software Foundation, Inc. |
9303 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9303
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
9303 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9303
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9303
diff
changeset
|
7 (at your option) any later version. |
9303 | 8 |
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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
9303 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <stdio.h> | |
12489 | 22 |
23 #include "signature.h" | |
24 SIGNATURE_CHECK (freopen, FILE *, (char const *, char const *, FILE *)); | |
25 | |
15720
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
26 #include <errno.h> |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
27 #include <unistd.h> |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
28 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
29 #include "macros.h" |
9303 | 30 |
31 int | |
32 main () | |
33 { | |
15720
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
34 const char *filename = "test-freopen.txt"; |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
35 |
18528
17ce151b83ab
freopen: work around glibc bug with closed fd
Paul Eggert <eggert@cs.ucla.edu>
parents:
18189
diff
changeset
|
36 close (STDIN_FILENO); |
9303 | 37 ASSERT (freopen ("/dev/null", "r", stdin) != NULL); |
18528
17ce151b83ab
freopen: work around glibc bug with closed fd
Paul Eggert <eggert@cs.ucla.edu>
parents:
18189
diff
changeset
|
38 ASSERT (getchar () == EOF); |
17ce151b83ab
freopen: work around glibc bug with closed fd
Paul Eggert <eggert@cs.ucla.edu>
parents:
18189
diff
changeset
|
39 ASSERT (!ferror (stdin)); |
17ce151b83ab
freopen: work around glibc bug with closed fd
Paul Eggert <eggert@cs.ucla.edu>
parents:
18189
diff
changeset
|
40 ASSERT (feof (stdin)); |
9303 | 41 |
15720
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
42 #if 0 /* freopen (NULL, ...) is unsupported on most platforms. */ |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
43 /* Test that freopen() sets errno if someone else closes the stream |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
44 fd behind the back of stdio. */ |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
45 { |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
46 FILE *fp = fopen (filename, "w+"); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
47 ASSERT (fp != NULL); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
48 ASSERT (close (fileno (fp)) == 0); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
49 errno = 0; |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
50 ASSERT (freopen (NULL, "r", fp) == NULL); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
51 perror("freopen"); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
52 ASSERT (errno == EBADF); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
53 fclose (fp); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
54 } |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
55 |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
56 /* Test that freopen() sets errno if the stream was constructed with |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
57 an invalid file descriptor. */ |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
58 { |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
59 FILE *fp = fdopen (-1, "w+"); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
60 if (fp != NULL) |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
61 { |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
62 errno = 0; |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
63 ASSERT (freopen (NULL, "r", fp) == NULL); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
64 ASSERT (errno == EBADF); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
65 fclose (fp); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
66 } |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
67 } |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
68 { |
17292
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
69 FILE *fp; |
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
70 close (99); |
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
71 fp = fdopen (99, "w+"); |
15720
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
72 if (fp != NULL) |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
73 { |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
74 errno = 0; |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
75 ASSERT (freopen (NULL, "r", fp) == NULL); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
76 ASSERT (errno == EBADF); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
77 fclose (fp); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
78 } |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
79 } |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
80 #endif |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
81 |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
82 /* Clean up. */ |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
83 unlink (filename); |
3a20a51c1323
freopen tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
84 |
9303 | 85 return 0; |
86 } |