manual: glob: document the gl_flags field
[glibc.git] / io / bits / fcntl2.h
blobf8f7fc73ea2fc50106ad83912b878f72a8d30c41
1 /* Checking macros for fcntl functions.
2 Copyright (C) 2007-2013 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 <http://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 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
35 __errordecl (__open_too_many_args,
36 "open can be called either with 2 or 3 arguments, not more");
37 __errordecl (__open_missing_mode,
38 "open with O_CREAT in second argument needs 3 arguments");
40 __fortify_function int
41 open (const char *__path, int __oflag, ...)
43 if (__va_arg_pack_len () > 1)
44 __open_too_many_args ();
46 if (__builtin_constant_p (__oflag))
48 if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
50 __open_missing_mode ();
51 return __open_2 (__path, __oflag);
53 return __open_alias (__path, __oflag, __va_arg_pack ());
56 if (__va_arg_pack_len () < 1)
57 return __open_2 (__path, __oflag);
59 return __open_alias (__path, __oflag, __va_arg_pack ());
63 #ifdef __USE_LARGEFILE64
64 extern int __open64_2 (const char *__path, int __oflag) __nonnull ((1));
65 extern int __REDIRECT (__open64_alias, (const char *__path, int __oflag,
66 ...), open64) __nonnull ((1));
67 __errordecl (__open64_too_many_args,
68 "open64 can be called either with 2 or 3 arguments, not more");
69 __errordecl (__open64_missing_mode,
70 "open64 with O_CREAT in second argument needs 3 arguments");
72 __fortify_function int
73 open64 (const char *__path, int __oflag, ...)
75 if (__va_arg_pack_len () > 1)
76 __open64_too_many_args ();
78 if (__builtin_constant_p (__oflag))
80 if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
82 __open64_missing_mode ();
83 return __open64_2 (__path, __oflag);
85 return __open64_alias (__path, __oflag, __va_arg_pack ());
88 if (__va_arg_pack_len () < 1)
89 return __open64_2 (__path, __oflag);
91 return __open64_alias (__path, __oflag, __va_arg_pack ());
93 #endif
96 #ifdef __USE_ATFILE
97 # ifndef __USE_FILE_OFFSET64
98 extern int __openat_2 (int __fd, const char *__path, int __oflag)
99 __nonnull ((2));
100 extern int __REDIRECT (__openat_alias, (int __fd, const char *__path,
101 int __oflag, ...), openat)
102 __nonnull ((2));
103 # else
104 extern int __REDIRECT (__openat_2, (int __fd, const char *__path,
105 int __oflag), __openat64_2)
106 __nonnull ((2));
107 extern int __REDIRECT (__openat_alias, (int __fd, const char *__path,
108 int __oflag, ...), openat64)
109 __nonnull ((2));
110 # endif
111 __errordecl (__openat_too_many_args,
112 "openat can be called either with 3 or 4 arguments, not more");
113 __errordecl (__openat_missing_mode,
114 "openat with O_CREAT in third argument needs 4 arguments");
116 __fortify_function int
117 openat (int __fd, const char *__path, int __oflag, ...)
119 if (__va_arg_pack_len () > 1)
120 __openat_too_many_args ();
122 if (__builtin_constant_p (__oflag))
124 if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
126 __openat_missing_mode ();
127 return __openat_2 (__fd, __path, __oflag);
129 return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
132 if (__va_arg_pack_len () < 1)
133 return __openat_2 (__fd, __path, __oflag);
135 return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
139 # ifdef __USE_LARGEFILE64
140 extern int __openat64_2 (int __fd, const char *__path, int __oflag)
141 __nonnull ((2));
142 extern int __REDIRECT (__openat64_alias, (int __fd, const char *__path,
143 int __oflag, ...), openat64)
144 __nonnull ((2));
145 __errordecl (__openat64_too_many_args,
146 "openat64 can be called either with 3 or 4 arguments, not more");
147 __errordecl (__openat64_missing_mode,
148 "openat64 with O_CREAT in third argument needs 4 arguments");
150 __fortify_function int
151 openat64 (int __fd, const char *__path, int __oflag, ...)
153 if (__va_arg_pack_len () > 1)
154 __openat64_too_many_args ();
156 if (__builtin_constant_p (__oflag))
158 if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
160 __openat64_missing_mode ();
161 return __openat64_2 (__fd, __path, __oflag);
163 return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
166 if (__va_arg_pack_len () < 1)
167 return __openat64_2 (__fd, __path, __oflag);
169 return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
171 # endif
172 #endif