]> git.ipfire.org Git - thirdparty/glibc.git/blame - io/bits/fcntl2.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / io / bits / fcntl2.h
CommitLineData
ddfd0535 1/* Checking macros for fcntl functions.
04277e02 2 Copyright (C) 2007-2019 Free Software Foundation, Inc.
ddfd0535
UD
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
ddfd0535
UD
18
19#ifndef _FCNTL_H
20# error "Never include <bits/fcntl2.h> directly; use <fcntl.h> instead."
21#endif
22
65f6f938 23/* Check that calls to open and openat with O_CREAT or O_TMPFILE set have an
ddfd0535
UD
24 appropriate third/fourth parameter. */
25#ifndef __USE_FILE_OFFSET64
a784e502
UD
26extern int __open_2 (const char *__path, int __oflag) __nonnull ((1));
27extern int __REDIRECT (__open_alias, (const char *__path, int __oflag, ...),
3a50811c 28 open) __nonnull ((1));
ddfd0535 29#else
a784e502 30extern int __REDIRECT (__open_2, (const char *__path, int __oflag),
ddfd0535 31 __open64_2) __nonnull ((1));
a784e502 32extern int __REDIRECT (__open_alias, (const char *__path, int __oflag, ...),
3a50811c 33 open64) __nonnull ((1));
ddfd0535 34#endif
3a50811c
UD
35__errordecl (__open_too_many_args,
36 "open can be called either with 2 or 3 arguments, not more");
37__errordecl (__open_missing_mode,
65f6f938 38 "open with O_CREAT or O_TMPFILE in second argument needs 3 arguments");
ddfd0535 39
5ac3ea17 40__fortify_function int
a784e502 41open (const char *__path, int __oflag, ...)
3a50811c
UD
42{
43 if (__va_arg_pack_len () > 1)
44 __open_too_many_args ();
45
46 if (__builtin_constant_p (__oflag))
47 {
65f6f938 48 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
3a50811c
UD
49 {
50 __open_missing_mode ();
51 return __open_2 (__path, __oflag);
52 }
53 return __open_alias (__path, __oflag, __va_arg_pack ());
54 }
55
56 if (__va_arg_pack_len () < 1)
57 return __open_2 (__path, __oflag);
58
59 return __open_alias (__path, __oflag, __va_arg_pack ());
60}
ddfd0535
UD
61
62
63#ifdef __USE_LARGEFILE64
a784e502
UD
64extern int __open64_2 (const char *__path, int __oflag) __nonnull ((1));
65extern int __REDIRECT (__open64_alias, (const char *__path, int __oflag,
3a50811c
UD
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,
65f6f938 70 "open64 with O_CREAT or O_TMPFILE in second argument needs 3 arguments");
3a50811c 71
5ac3ea17 72__fortify_function int
a784e502 73open64 (const char *__path, int __oflag, ...)
3a50811c
UD
74{
75 if (__va_arg_pack_len () > 1)
76 __open64_too_many_args ();
ddfd0535 77
3a50811c
UD
78 if (__builtin_constant_p (__oflag))
79 {
65f6f938 80 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
3a50811c
UD
81 {
82 __open64_missing_mode ();
83 return __open64_2 (__path, __oflag);
84 }
85 return __open64_alias (__path, __oflag, __va_arg_pack ());
86 }
87
88 if (__va_arg_pack_len () < 1)
89 return __open64_2 (__path, __oflag);
90
91 return __open64_alias (__path, __oflag, __va_arg_pack ());
92}
ddfd0535
UD
93#endif
94
3a50811c 95
ddfd0535
UD
96#ifdef __USE_ATFILE
97# ifndef __USE_FILE_OFFSET64
a784e502 98extern int __openat_2 (int __fd, const char *__path, int __oflag)
47ad95ab 99 __nonnull ((2));
a784e502 100extern int __REDIRECT (__openat_alias, (int __fd, const char *__path,
3a50811c
UD
101 int __oflag, ...), openat)
102 __nonnull ((2));
ddfd0535 103# else
a784e502 104extern int __REDIRECT (__openat_2, (int __fd, const char *__path,
ddfd0535 105 int __oflag), __openat64_2)
47ad95ab 106 __nonnull ((2));
a784e502 107extern int __REDIRECT (__openat_alias, (int __fd, const char *__path,
3a50811c
UD
108 int __oflag, ...), openat64)
109 __nonnull ((2));
ddfd0535 110# endif
3a50811c
UD
111__errordecl (__openat_too_many_args,
112 "openat can be called either with 3 or 4 arguments, not more");
113__errordecl (__openat_missing_mode,
65f6f938 114 "openat with O_CREAT or O_TMPFILE in third argument needs 4 arguments");
3a50811c 115
5ac3ea17 116__fortify_function int
a784e502 117openat (int __fd, const char *__path, int __oflag, ...)
3a50811c
UD
118{
119 if (__va_arg_pack_len () > 1)
120 __openat_too_many_args ();
121
122 if (__builtin_constant_p (__oflag))
123 {
65f6f938 124 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
3a50811c
UD
125 {
126 __openat_missing_mode ();
127 return __openat_2 (__fd, __path, __oflag);
128 }
129 return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
130 }
131
132 if (__va_arg_pack_len () < 1)
133 return __openat_2 (__fd, __path, __oflag);
ddfd0535 134
3a50811c
UD
135 return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
136}
ddfd0535
UD
137
138
139# ifdef __USE_LARGEFILE64
a784e502 140extern int __openat64_2 (int __fd, const char *__path, int __oflag)
47ad95ab 141 __nonnull ((2));
a784e502 142extern int __REDIRECT (__openat64_alias, (int __fd, const char *__path,
3a50811c
UD
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,
65f6f938 148 "openat64 with O_CREAT or O_TMPFILE in third argument needs 4 arguments");
3a50811c 149
5ac3ea17 150__fortify_function int
a784e502 151openat64 (int __fd, const char *__path, int __oflag, ...)
3a50811c
UD
152{
153 if (__va_arg_pack_len () > 1)
154 __openat64_too_many_args ();
155
156 if (__builtin_constant_p (__oflag))
157 {
65f6f938 158 if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)
3a50811c
UD
159 {
160 __openat64_missing_mode ();
161 return __openat64_2 (__fd, __path, __oflag);
162 }
163 return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
164 }
165
166 if (__va_arg_pack_len () < 1)
167 return __openat64_2 (__fd, __path, __oflag);
ddfd0535 168
3a50811c
UD
169 return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
170}
ddfd0535
UD
171# endif
172#endif