annotate tests/test-fopen.c @ 11849:18b5c404aa04

tests: test some of the *-safer modules * modules/fopen-safer (Depends-on): Add fopen. * modules/fcntl-safer (Depends-on): Add fcntl. * modules/stdlib-safer (Depends-on): Add stdlib. (configure.ac): Set indicator. * modules/unistd-safer (configure.ac): Likewise. * modules/tmpfile-safer (configure.ac): Likewise. (Depends-on): Add tmpfile. * lib/stdio--.h (fopen, tmpfile): Don't override unless module is active. * tests/test-fopen.c (includes): Test safer versions when they are in use. * tests/test-open.c (includes): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Wed, 19 Aug 2009 09:54:54 -0600
parents a4dc39a18d54
children f455bec0d65f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of opening a file stream.
11849
18b5c404aa04 tests: test some of the *-safer modules
Eric Blake <ebb9@byu.net>
parents: 10472
diff changeset
2 Copyright (C) 2007-2009 Free Software Foundation, Inc.
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9302
diff changeset
4 This program is free software: you can redistribute it and/or modify
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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: 9302
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: 9302
diff changeset
7 (at your option) any later version.
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9302
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdio.h>
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <stdlib.h>
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
11849
18b5c404aa04 tests: test some of the *-safer modules
Eric Blake <ebb9@byu.net>
parents: 10472
diff changeset
24 #if GNULIB_FOPEN_SAFER
18b5c404aa04 tests: test some of the *-safer modules
Eric Blake <ebb9@byu.net>
parents: 10472
diff changeset
25 # include "stdio--.h"
18b5c404aa04 tests: test some of the *-safer modules
Eric Blake <ebb9@byu.net>
parents: 10472
diff changeset
26 #endif
18b5c404aa04 tests: test some of the *-safer modules
Eric Blake <ebb9@byu.net>
parents: 10472
diff changeset
27
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #define ASSERT(expr) \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 do \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 { \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 if (!(expr)) \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 { \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
34 fflush (stderr); \
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 abort (); \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 } \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 } \
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 while (0)
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 int
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 main ()
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 {
10376
8532ecccedda Work around bug with trailing slash on Solaris 9 and HP-UX 11.00.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
43 ASSERT (fopen ("nonexist.ent/", "w") == NULL);
10472
a4dc39a18d54 Ensure that a filename ending in a slash cannot be used to access a non-directory.
Bruno Haible <bruno@clisp.org>
parents: 10376
diff changeset
44 ASSERT (fopen ("/dev/null/", "r") == NULL);
10376
8532ecccedda Work around bug with trailing slash on Solaris 9 and HP-UX 11.00.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
45
9302
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 ASSERT (fopen ("/dev/null", "r") != NULL);
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 return 0;
e0a1dcc13fb9 Test for module 'fopen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 }