fcntl2.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Checking macros for fcntl functions.
  2. Copyright (C) 2007 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _FCNTL_H
  17. # error "Never include <bits/fcntl2.h> directly; use <fcntl.h> instead."
  18. #endif
  19. /* Check that calls to open and openat with O_CREAT set have an
  20. appropriate third/fourth parameter. */
  21. #ifndef __USE_FILE_OFFSET64
  22. extern int __open_2 (__const char *__path, int __oflag) __nonnull ((1));
  23. extern int __REDIRECT (__open_alias, (__const char *__path, int __oflag, ...),
  24. open) __nonnull ((1));
  25. #else
  26. extern int __REDIRECT (__open_2, (__const char *__path, int __oflag),
  27. __open64_2) __nonnull ((1));
  28. extern int __REDIRECT (__open_alias, (__const char *__path, int __oflag, ...),
  29. open64) __nonnull ((1));
  30. #endif
  31. __errordecl (__open_too_many_args,
  32. "open can be called either with 2 or 3 arguments, not more");
  33. __errordecl (__open_missing_mode,
  34. "open with O_CREAT in second argument needs 3 arguments");
  35. __extern_always_inline int
  36. open (__const char *__path, int __oflag, ...)
  37. {
  38. if (__va_arg_pack_len () > 1)
  39. __open_too_many_args ();
  40. if (__builtin_constant_p (__oflag))
  41. {
  42. if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
  43. {
  44. __open_missing_mode ();
  45. return __open_2 (__path, __oflag);
  46. }
  47. return __open_alias (__path, __oflag, __va_arg_pack ());
  48. }
  49. if (__va_arg_pack_len () < 1)
  50. return __open_2 (__path, __oflag);
  51. return __open_alias (__path, __oflag, __va_arg_pack ());
  52. }
  53. #ifdef __USE_LARGEFILE64
  54. extern int __open64_2 (__const char *__path, int __oflag) __nonnull ((1));
  55. extern int __REDIRECT (__open64_alias, (__const char *__path, int __oflag,
  56. ...), open64) __nonnull ((1));
  57. __errordecl (__open64_too_many_args,
  58. "open64 can be called either with 2 or 3 arguments, not more");
  59. __errordecl (__open64_missing_mode,
  60. "open64 with O_CREAT in second argument needs 3 arguments");
  61. __extern_always_inline int
  62. open64 (__const char *__path, int __oflag, ...)
  63. {
  64. if (__va_arg_pack_len () > 1)
  65. __open64_too_many_args ();
  66. if (__builtin_constant_p (__oflag))
  67. {
  68. if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
  69. {
  70. __open64_missing_mode ();
  71. return __open64_2 (__path, __oflag);
  72. }
  73. return __open64_alias (__path, __oflag, __va_arg_pack ());
  74. }
  75. if (__va_arg_pack_len () < 1)
  76. return __open64_2 (__path, __oflag);
  77. return __open64_alias (__path, __oflag, __va_arg_pack ());
  78. }
  79. #endif
  80. #ifdef __USE_ATFILE
  81. # ifndef __USE_FILE_OFFSET64
  82. extern int __openat_2 (int __fd, __const char *__path, int __oflag)
  83. __nonnull ((2));
  84. extern int __REDIRECT (__openat_alias, (int __fd, __const char *__path,
  85. int __oflag, ...), openat)
  86. __nonnull ((2));
  87. # else
  88. extern int __REDIRECT (__openat_2, (int __fd, __const char *__path,
  89. int __oflag), __openat64_2)
  90. __nonnull ((2));
  91. extern int __REDIRECT (__openat_alias, (int __fd, __const char *__path,
  92. int __oflag, ...), openat64)
  93. __nonnull ((2));
  94. # endif
  95. __errordecl (__openat_too_many_args,
  96. "openat can be called either with 3 or 4 arguments, not more");
  97. __errordecl (__openat_missing_mode,
  98. "openat with O_CREAT in third argument needs 4 arguments");
  99. __extern_always_inline int
  100. openat (int __fd, __const char *__path, int __oflag, ...)
  101. {
  102. if (__va_arg_pack_len () > 1)
  103. __openat_too_many_args ();
  104. if (__builtin_constant_p (__oflag))
  105. {
  106. if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
  107. {
  108. __openat_missing_mode ();
  109. return __openat_2 (__fd, __path, __oflag);
  110. }
  111. return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
  112. }
  113. if (__va_arg_pack_len () < 1)
  114. return __openat_2 (__fd, __path, __oflag);
  115. return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
  116. }
  117. # ifdef __USE_LARGEFILE64
  118. extern int __openat64_2 (int __fd, __const char *__path, int __oflag)
  119. __nonnull ((2));
  120. extern int __REDIRECT (__openat64_alias, (int __fd, __const char *__path,
  121. int __oflag, ...), openat64)
  122. __nonnull ((2));
  123. __errordecl (__openat64_too_many_args,
  124. "openat64 can be called either with 3 or 4 arguments, not more");
  125. __errordecl (__openat64_missing_mode,
  126. "openat64 with O_CREAT in third argument needs 4 arguments");
  127. __extern_always_inline int
  128. openat64 (int __fd, __const char *__path, int __oflag, ...)
  129. {
  130. if (__va_arg_pack_len () > 1)
  131. __openat64_too_many_args ();
  132. if (__builtin_constant_p (__oflag))
  133. {
  134. if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
  135. {
  136. __openat64_missing_mode ();
  137. return __openat64_2 (__fd, __path, __oflag);
  138. }
  139. return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
  140. }
  141. if (__va_arg_pack_len () < 1)
  142. return __openat64_2 (__fd, __path, __oflag);
  143. return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
  144. }
  145. # endif
  146. #endif