1/* Checking macros for fcntl functions. Linux version.
2 Copyright (C) 2025-2026 Free Software Foundation, Inc.
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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _FCNTL_H
20# error "Never include <bits/fcntl-linux-fortify.h> directly; use <fcntl.h> instead."
21#endif
22
23#ifdef __USE_GNU
24
25extern int __REDIRECT (__openat2_alias, (int __dfd, const char *__filename,
26 const struct open_how *__how,
27 size_t __usize), openat2)
28 __nonnull ((2, 3));
29
30#if !__fortify_use_clang
31__errordecl (__openat2_invalid_size,
32 "the specified size is larger than sizeof (struct open_how)");
33#endif
34
35__fortify_function int
36openat2 (int __dfd, const char *__filename, const struct open_how *__how,
37 size_t __usize)
38 __fortify_clang_warning (__builtin_constant_p (__usize)
39 && __usize > sizeof (struct open_how),
40 "the specified size is larger than sizeof (struct open_how)")
41{
42#if !__fortify_use_clang
43 if (__builtin_constant_p (__usize) && __usize > sizeof (struct open_how))
44 __openat2_invalid_size ();
45#endif
46 return __openat2_alias (__dfd, __filename, __how, __usize);
47}
48
49#endif /* use GNU */