elf/Makefile: Split and sort PIE tests
[glibc.git] / io / bits / fcntl2.h
blob26f1792fd1afa3efbcbe0176b2280d0956dffc73
1 /* Checking macros for fcntl functions.
2 Copyright (C) 2007-2024 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, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _FCNTL_H
20 # error "Never include <bits/fcntl2.h> directly; use <fcntl.h> instead."
21 #endif
23 /* Check that calls to open and openat with O_CREAT or O_TMPFILE set have an
24 appropriate third/fourth parameter. */
25 #ifndef __USE_FILE_OFFSET64
26 extern int __open_2 (const char *__path, int __oflag) __nonnull ((1));
27 extern int __REDIRECT (__open_alias, (const char *__path, int __oflag, ...),
28 open) __nonnull ((1));
29 #else
30 extern int __REDIRECT (__open_2, (const char *__path, int __oflag),
31 __open64_2) __nonnull ((1));
32 extern int __REDIRECT (__open_alias, (const char *__path, int __oflag, ...),
33 open64) __nonnull ((1));
34 #endif
36 #ifdef __va_arg_pack_len
37 __errordecl (__open_too_many_args,
38 "open can be called either with 2 or 3 arguments, not more");
39 __errordecl (__open_missing_mode,
40 "open with O_CREAT or O_TMPFILE in second argument needs 3 arguments");
42 __fortify_function int
43 open (const char *__path, int __oflag, ...)
45 if (__va_arg_pack_len () > 1)
46 __open_too_many_args ();
48 if (__builtin_constant_p (__oflag))
50 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
52 __open_missing_mode ();
53 return __open_2 (__path, __oflag);
55 return __open_alias (__path, __oflag, __va_arg_pack ());
58 if (__va_arg_pack_len () < 1)
59 return __open_2 (__path, __oflag);
61 return __open_alias (__path, __oflag, __va_arg_pack ());
63 #elif __fortify_use_clang
64 __fortify_function_error_function __attribute_overloadable__ int
65 open (const char *__path, int __oflag, mode_t __mode, ...)
66 __fortify_clang_unavailable ("open can be called either with 2 or 3 arguments, not more");
68 __fortify_function __attribute_overloadable__ int
69 open (__fortify_clang_overload_arg (const char *, ,__path), int __oflag)
70 __fortify_clang_prefer_this_overload
71 __fortify_clang_error (__OPEN_NEEDS_MODE (__oflag),
72 "open with O_CREAT or O_TMPFILE in second argument needs 3 arguments")
74 return __open_2 (__path, __oflag);
77 __fortify_function __attribute_overloadable__ int
78 open (__fortify_clang_overload_arg (const char *, ,__path), int __oflag,
79 mode_t __mode)
81 return __open_alias (__path, __oflag, __mode);
83 #endif
86 #ifdef __USE_LARGEFILE64
87 extern int __open64_2 (const char *__path, int __oflag) __nonnull ((1));
88 extern int __REDIRECT (__open64_alias, (const char *__path, int __oflag,
89 ...), open64) __nonnull ((1));
90 # ifdef __va_arg_pack_len
91 __errordecl (__open64_too_many_args,
92 "open64 can be called either with 2 or 3 arguments, not more");
93 __errordecl (__open64_missing_mode,
94 "open64 with O_CREAT or O_TMPFILE in second argument needs 3 arguments");
96 __fortify_function int
97 open64 (const char *__path, int __oflag, ...)
99 if (__va_arg_pack_len () > 1)
100 __open64_too_many_args ();
102 if (__builtin_constant_p (__oflag))
104 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
106 __open64_missing_mode ();
107 return __open64_2 (__path, __oflag);
109 return __open64_alias (__path, __oflag, __va_arg_pack ());
112 if (__va_arg_pack_len () < 1)
113 return __open64_2 (__path, __oflag);
115 return __open64_alias (__path, __oflag, __va_arg_pack ());
117 # elif __fortify_use_clang
118 __fortify_function_error_function __attribute_overloadable__ int
119 open64 (const char *__path, int __oflag, mode_t __mode, ...)
120 __fortify_clang_unavailable ("open64 can be called either with 2 or 3 arguments, not more");
122 __fortify_function __attribute_overloadable__ int
123 open64 (__fortify_clang_overload_arg (const char *, ,__path), int __oflag)
124 __fortify_clang_prefer_this_overload
125 __fortify_clang_error (__OPEN_NEEDS_MODE (__oflag),
126 "open64 with O_CREAT or O_TMPFILE in second argument needs 3 arguments")
128 return __open64_2 (__path, __oflag);
131 __fortify_function __attribute_overloadable__ int
132 open64 (__fortify_clang_overload_arg (const char *, ,__path), int __oflag,
133 mode_t __mode)
135 return __open64_alias (__path, __oflag, __mode);
137 # endif
138 #endif
141 #ifdef __USE_ATFILE
142 # ifndef __USE_FILE_OFFSET64
143 extern int __openat_2 (int __fd, const char *__path, int __oflag)
144 __nonnull ((2));
145 extern int __REDIRECT (__openat_alias, (int __fd, const char *__path,
146 int __oflag, ...), openat)
147 __nonnull ((2));
148 # else
149 extern int __REDIRECT (__openat_2, (int __fd, const char *__path,
150 int __oflag), __openat64_2)
151 __nonnull ((2));
152 extern int __REDIRECT (__openat_alias, (int __fd, const char *__path,
153 int __oflag, ...), openat64)
154 __nonnull ((2));
155 # endif
157 # ifdef __va_arg_pack_len
158 __errordecl (__openat_too_many_args,
159 "openat can be called either with 3 or 4 arguments, not more");
160 __errordecl (__openat_missing_mode,
161 "openat with O_CREAT or O_TMPFILE in third argument needs 4 arguments");
163 __fortify_function int
164 openat (int __fd, const char *__path, int __oflag, ...)
166 if (__va_arg_pack_len () > 1)
167 __openat_too_many_args ();
169 if (__builtin_constant_p (__oflag))
171 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
173 __openat_missing_mode ();
174 return __openat_2 (__fd, __path, __oflag);
176 return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
179 if (__va_arg_pack_len () < 1)
180 return __openat_2 (__fd, __path, __oflag);
182 return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
184 # elif __fortify_use_clang
185 __fortify_function_error_function __attribute_overloadable__ int
186 openat (int __fd, const char *__path, int __oflag, mode_t __mode, ...)
187 __fortify_clang_unavailable ("openat can be called either with 3 or 4 arguments, not more");
189 __fortify_function __attribute_overloadable__ int
190 openat (int __fd, __fortify_clang_overload_arg (const char *, ,__path),
191 int __oflag)
192 __fortify_clang_prefer_this_overload
193 __fortify_clang_error (__OPEN_NEEDS_MODE (__oflag),
194 "openat with O_CREAT or O_TMPFILE in third argument needs 4 arguments")
196 return __openat_2 (__fd, __path, __oflag);
199 __fortify_function __attribute_overloadable__ int
200 openat (int __fd, __fortify_clang_overload_arg (const char *, ,__path),
201 int __oflag, mode_t __mode)
203 return __openat_alias (__fd, __path, __oflag, __mode);
205 # endif
208 # ifdef __USE_LARGEFILE64
209 extern int __openat64_2 (int __fd, const char *__path, int __oflag)
210 __nonnull ((2));
211 extern int __REDIRECT (__openat64_alias, (int __fd, const char *__path,
212 int __oflag, ...), openat64)
213 __nonnull ((2));
214 __errordecl (__openat64_too_many_args,
215 "openat64 can be called either with 3 or 4 arguments, not more");
216 __errordecl (__openat64_missing_mode,
217 "openat64 with O_CREAT or O_TMPFILE in third argument needs 4 arguments");
219 # ifdef __va_arg_pack_len
220 __fortify_function int
221 openat64 (int __fd, const char *__path, int __oflag, ...)
223 if (__va_arg_pack_len () > 1)
224 __openat64_too_many_args ();
226 if (__builtin_constant_p (__oflag))
228 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
230 __openat64_missing_mode ();
231 return __openat64_2 (__fd, __path, __oflag);
233 return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
236 if (__va_arg_pack_len () < 1)
237 return __openat64_2 (__fd, __path, __oflag);
239 return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
241 # elif __fortify_use_clang
242 __fortify_function_error_function __attribute_overloadable__ int
243 openat64 (int __fd, const char *__path, int __oflag, mode_t __mode, ...)
244 __fortify_clang_unavailable ("openat64 can be called either with 3 or 4 arguments, not more");
246 __fortify_function __attribute_overloadable__ int
247 openat64 (int __fd, __fortify_clang_overload_arg (const char *, ,__path),
248 int __oflag)
249 __fortify_clang_prefer_this_overload
250 __fortify_clang_error (__OPEN_NEEDS_MODE (__oflag),
251 "openat64 with O_CREAT or O_TMPFILE in third argument needs 4 arguments")
253 return __openat64_2 (__fd, __path, __oflag);
256 __fortify_function __attribute_overloadable__ int
257 openat64 (int __fd, __fortify_clang_overload_arg (const char *, ,__path),
258 int __oflag, mode_t __mode)
260 return __openat64_alias (__fd, __path, __oflag, __mode);
262 # endif
263 # endif
264 #endif