Support for MSVC compiler: Ensure off_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 off_t t2;
37
38 int
39 main (void)
40 {
41   /* Ensure no overlap in SEEK_*. */
42   switch (0)
43     {
44     case SEEK_CUR:
45     case SEEK_END:
46     case SEEK_SET:
47       ;
48     }
49
50   /* Ensure no dangerous overlap in non-zero gnulib-defined replacements.  */
51   switch (O_RDONLY)
52     {
53       /* Access modes */
54     case O_RDONLY:
55     case O_WRONLY:
56     case O_RDWR:
57 #if O_EXEC && O_EXEC != O_RDONLY
58     case O_EXEC:
59 #endif
60 #if O_SEARCH && O_EXEC != O_SEARCH && O_SEARCH != O_RDONLY
61     case O_SEARCH:
62 #endif
63       i = O_ACCMODE == (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH);
64       break;
65
66       /* Everyone should have these */
67     case O_CREAT:
68     case O_EXCL:
69     case O_TRUNC:
70     case O_APPEND:
71       break;
72
73       /* These might be 0 or O_RDONLY, only test non-zero versions.  */
74 #if O_CLOEXEC
75     case O_CLOEXEC:
76 #endif
77 #if O_DIRECT
78     case O_DIRECT:
79 #endif
80 #if O_DIRECTORY
81     case O_DIRECTORY:
82 #endif
83 #if O_DSYNC
84     case O_DSYNC:
85 #endif
86 #if O_NOATIME
87     case O_NOATIME:
88 #endif
89 #if O_NONBLOCK
90     case O_NONBLOCK:
91 #endif
92 #if O_NOCTTY
93     case O_NOCTTY:
94 #endif
95 #if O_NOFOLLOW
96     case O_NOFOLLOW:
97 #endif
98 #if O_NOLINKS
99     case O_NOLINKS:
100 #endif
101 #if O_RSYNC && O_RSYNC != O_DSYNC
102     case O_RSYNC:
103 #endif
104 #if O_SYNC && O_SYNC != O_RSYNC
105     case O_SYNC:
106 #endif
107 #if O_TTY_INIT
108     case O_TTY_INIT:
109 #endif
110 #if O_BINARY
111     case O_BINARY:
112 #endif
113 #if O_TEXT
114     case O_TEXT:
115 #endif
116       ;
117     }
118
119   return !i;
120 }