fcntl-linux-fortify.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Checking macros for fcntl functions. Linux version.
  17. Copyright (C) 2025-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #ifndef _FCNTL_H
  31. # error "Never include <bits/fcntl-linux-fortify.h> directly; use <fcntl.h> instead."
  32. #endif
  33. #ifdef __USE_GNU
  34. extern int __REDIRECT (__openat2_alias, (int __dfd, const char *__filename,
  35. const struct open_how *__how,
  36. size_t __usize), openat2)
  37. __nonnull ((2, 3));
  38. #if !__fortify_use_clang
  39. __errordecl (__openat2_invalid_size,
  40. "the specified size is larger than sizeof (struct open_how)");
  41. #endif
  42. __fortify_function int
  43. openat2 (int __dfd, const char *__filename, const struct open_how *__how,
  44. size_t __usize)
  45. __fortify_clang_warning (__builtin_constant_p (__usize)
  46. && __usize > sizeof (struct open_how),
  47. "the specified size is larger than sizeof (struct open_how)")
  48. {
  49. #if !__fortify_use_clang
  50. if (__builtin_constant_p (__usize) && __usize > sizeof (struct open_how))
  51. __openat2_invalid_size ();
  52. #endif
  53. return __openat2_alias (__dfd, __filename, __how, __usize);
  54. }
  55. #endif /* use GNU */