b1dafbb21300ca3380880289c8d52b189ef62094
[gnulib.git] / test-fopen.h
1 /* Test of opening a file stream.
2    Copyright (C) 2007-2009 Free Software Foundation, Inc.
3
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 of the License, or
7    (at your option) any later version.
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
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
18
19 /* Include <config.h> and a form of <stdio.h> first.  */
20
21 #include <stdlib.h>
22
23 #define ASSERT(expr) \
24   do                                                                         \
25     {                                                                        \
26       if (!(expr))                                                           \
27         {                                                                    \
28           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
29           fflush (stderr);                                                   \
30           abort ();                                                          \
31         }                                                                    \
32     }                                                                        \
33   while (0)
34
35 int
36 main ()
37 {
38   ASSERT (fopen ("nonexist.ent/", "w") == NULL);
39   ASSERT (fopen ("/dev/null/", "r") == NULL);
40
41   ASSERT (fopen ("/dev/null", "r") != NULL);
42
43   return 0;
44 }