1 /* Checking macros for fcntl functions.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # error "Never include <bits/fcntl2.h> directly; use <fcntl.h> instead."
24 /* Check that calls to open and openat with O_CREAT set have an
25 appropriate third/fourth parameter. */
26 #ifndef __USE_FILE_OFFSET64
27 extern int __open_2 (__const
char *__path
, int __oflag
) __nonnull ((1));
29 extern int __REDIRECT (__open_2
, (__const
char *__file
, int __oflag
),
30 __open64_2
) __nonnull ((1));
33 #define open(fname, flags, ...) \
36 /* If the compiler complains about an invalid type, excess elements, \
37 etc. in the initialization this means a parameter of the wrong type \
38 has been passed to open. */ \
39 int ___arr[] = { __VA_ARGS__ }; \
40 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0) \
42 /* If the compiler complains about the size of this array type the \
43 mode parameter is missing since O_CREAT has been used. */ \
44 typedef int __open_missing_mode[((flags) & O_CREAT) != 0 \
45 ? ((long int) sizeof (___arr) \
46 - (long int) sizeof (int)) : 1];\
48 if (sizeof (___arr) == 0) \
50 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0) \
51 ___r = open (fname, flags); \
53 ___r = __open_2 (fname, flags); \
57 /* If the compiler complains about the size of this array type too \
58 many parameters have been passed to open. */ \
59 typedef int __open_too_many_args[-(sizeof (___arr) \
61 ___r = open (fname, flags, ___arr[0]); \
67 #ifdef __USE_LARGEFILE64
68 extern int __open64_2 (__const
char *__path
, int __oflag
) __nonnull ((1));
70 # define open64(fname, flags, ...) \
73 /* If the compiler complains about an invalid type, excess elements, \
74 etc. in the initialization this means a parameter of the wrong type \
75 has been passed to open64. */ \
76 int ___arr[] = { __VA_ARGS__ }; \
77 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0) \
79 /* If the compiler complains about the size of this array type the \
80 mode parameter is missing since O_CREAT has been used. */ \
81 typedef int __open_missing_mode[((flags) & O_CREAT) != 0 \
82 ? ((long int) sizeof (___arr) \
83 - (long int) sizeof (int)) : 1];\
85 if (sizeof (___arr) == 0) \
87 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0) \
88 ___r = open64 (fname, flags); \
90 ___r = __open64_2 (fname, flags); \
94 /* If the compiler complains about the size of this array type too \
95 many parameters have been passed to open64. */ \
96 typedef int __open_too_many_args[-(sizeof (___arr) \
98 ___r = open64 (fname, flags, ___arr[0]); \
105 # ifndef __USE_FILE_OFFSET64
106 extern int __openat_2 (int __fd
, __const
char *__path
, int __oflag
)
109 extern int __REDIRECT (__openat_2
, (int __fd
, __const
char *__file
,
110 int __oflag
), __openat64_2
)
114 # define openat(fd, fname, flags, ...) \
117 /* If the compiler complains about an invalid type, excess elements, \
118 etc. in the initialization this means a parameter of the wrong type \
119 has been passed to openat. */ \
120 int ___arr[] = { __VA_ARGS__ }; \
121 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0) \
123 /* If the compiler complains about the size of this array type the \
124 mode parameter is missing since O_CREAT has been used. */ \
125 typedef int __open_missing_mode[((flags) & O_CREAT) != 0 \
126 ? ((long int) sizeof (___arr) \
127 - (long int) sizeof (int)) : 1];\
129 if (sizeof (___arr) == 0) \
131 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0) \
132 ___r = openat (fd, fname, flags); \
134 ___r = __openat_2 (fd, fname, flags); \
138 /* If the compiler complains about the size of this array type too \
139 many parameters have been passed to openat. */ \
140 typedef int __open_too_many_args[-(sizeof (___arr) \
142 ___r = openat (fd, fname, flags, ___arr[0]); \
148 # ifdef __USE_LARGEFILE64
149 extern int __openat64_2 (int __fd
, __const
char *__path
, int __oflag
)
152 # define openat64(fd, fname, flags, ...) \
155 /* If the compiler complains about an invalid type, excess elements, \
156 etc. in the initialization this means a parameter of the wrong type \
157 has been passed to openat64. */ \
158 int ___arr[] = { __VA_ARGS__ }; \
159 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0) \
161 /* If the compiler complains about the size of this array type the \
162 mode parameter is missing since O_CREAT has been used. */ \
163 typedef int __open_missing_mode[((flags) & O_CREAT) != 0 \
164 ? ((long int) sizeof (___arr) \
165 - (long int) sizeof (int)) : 1];\
167 if (sizeof (___arr) == 0) \
169 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0) \
170 ___r = openat64 (fd, fname, flags); \
172 ___r = __openat64_2 (fd, fname, flags); \
176 /* If the compiler complains about the size of this array type too \
177 many parameters have been passed to openat64. */ \
178 typedef int __open_too_many_args[-(sizeof (___arr) \
180 ___r = openat64 (fd, fname, flags, ___arr[0]); \