Ensure pid_t gets defined.
[gnulib.git] / tests / test-fcntl-h.c
1 /* Test of <fcntl.h> substitute.
2    Copyright (C) 2007, 2009-2011 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>
20
21 #include <fcntl.h>
22
23 /* Check that the various O_* macros are defined.  */
24 int o = O_DIRECT | O_DIRECTORY | O_DSYNC | O_NDELAY | O_NOATIME | O_NONBLOCK
25         | O_NOCTTY | O_NOFOLLOW | O_NOLINKS | O_RSYNC | O_SYNC | O_TTY_INIT
26         | O_BINARY | O_TEXT;
27
28 /* Check that the various SEEK_* macros are defined.  */
29 int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
30
31 /* Check that the FD_* macros are defined.  */
32 int i = FD_CLOEXEC;
33
34 /* Check that the types are all defined.  */
35 pid_t t1;
36
37 int
38 main (void)
39 {
40   /* Ensure no overlap in SEEK_*. */
41   switch (0)
42     {
43     case SEEK_CUR:
44     case SEEK_END:
45     case SEEK_SET:
46       ;
47     }
48
49   /* Ensure no dangerous overlap in non-zero gnulib-defined replacements.  */
50   switch (O_RDONLY)
51     {
52       /* Access modes */
53     case O_RDONLY:
54     case O_WRONLY:
55     case O_RDWR:
56 #if O_EXEC && O_EXEC != O_RDONLY
57     case O_EXEC:
58 #endif
59 #if O_SEARCH && O_EXEC != O_SEARCH && O_SEARCH != O_RDONLY
60     case O_SEARCH:
61 #endif
62       i = O_ACCMODE == (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH);
63       break;
64
65       /* Everyone should have these */
66     case O_CREAT:
67     case O_EXCL:
68     case O_TRUNC:
69     case O_APPEND:
70       break;
71
72       /* These might be 0 or O_RDONLY, only test non-zero versions.  */
73 #if O_CLOEXEC
74     case O_CLOEXEC:
75 #endif
76 #if O_DIRECT
77     case O_DIRECT:
78 #endif
79 #if O_DIRECTORY
80     case O_DIRECTORY:
81 #endif
82 #if O_DSYNC
83     case O_DSYNC:
84 #endif
85 #if O_NOATIME
86     case O_NOATIME:
87 #endif
88 #if O_NONBLOCK
89     case O_NONBLOCK:
90 #endif
91 #if O_NOCTTY
92     case O_NOCTTY:
93 #endif
94 #if O_NOFOLLOW
95     case O_NOFOLLOW:
96 #endif
97 #if O_NOLINKS
98     case O_NOLINKS:
99 #endif
100 #if O_RSYNC && O_RSYNC != O_DSYNC
101     case O_RSYNC:
102 #endif
103 #if O_SYNC && O_SYNC != O_RSYNC
104     case O_SYNC:
105 #endif
106 #if O_TTY_INIT
107     case O_TTY_INIT:
108 #endif
109 #if O_BINARY
110     case O_BINARY:
111 #endif
112 #if O_TEXT
113     case O_TEXT:
114 #endif
115       ;
116     }
117
118   return !i;
119 }