Mercurial > hg > octave-kai > gnulib-hg
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 |
rev | line source |
---|---|
9302 | 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 | 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 | 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 | 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 | |
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 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
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 | 28 #define ASSERT(expr) \ |
29 do \ | |
30 { \ | |
31 if (!(expr)) \ | |
32 { \ | |
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 | 35 abort (); \ |
36 } \ | |
37 } \ | |
38 while (0) | |
39 | |
40 int | |
41 main () | |
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 | 46 ASSERT (fopen ("/dev/null", "r") != NULL); |
47 | |
48 return 0; | |
49 } |