unistd.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* Checking macros for unistd functions.
  2. Copyright (C) 2005-2026 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, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _UNISTD_H
  16. # error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
  17. #endif
  18. # include <bits/unistd-decl.h>
  19. __fortify_function __attribute_overloadable__ __wur ssize_t
  20. read (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf), size_t __nbytes)
  21. __fortify_clang_warning_only_if_bos0_lt (__nbytes, __buf,
  22. "read called with bigger length than "
  23. "size of the destination buffer")
  24. {
  25. return __glibc_fortify (read, __nbytes, sizeof (char),
  26. __glibc_objsize0 (__buf),
  27. __fd, __buf, __nbytes);
  28. }
  29. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  30. # ifndef __USE_FILE_OFFSET64
  31. __fortify_function __attribute_overloadable__ __wur ssize_t
  32. pread (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf),
  33. size_t __nbytes, __off_t __offset)
  34. __fortify_clang_warning_only_if_bos0_lt (__nbytes, __buf,
  35. "pread called with bigger length than "
  36. "size of the destination buffer")
  37. {
  38. return __glibc_fortify (pread, __nbytes, sizeof (char),
  39. __glibc_objsize0 (__buf),
  40. __fd, __buf, __nbytes, __offset);
  41. }
  42. # else
  43. __fortify_function __attribute_overloadable__ __wur ssize_t
  44. pread (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf),
  45. size_t __nbytes, __off64_t __offset)
  46. __fortify_clang_warning_only_if_bos0_lt (__nbytes, __buf,
  47. "pread called with bigger length than "
  48. "size of the destination buffer")
  49. {
  50. return __glibc_fortify (pread64, __nbytes, sizeof (char),
  51. __glibc_objsize0 (__buf),
  52. __fd, __buf, __nbytes, __offset);
  53. }
  54. # endif
  55. # ifdef __USE_LARGEFILE64
  56. __fortify_function __attribute_overloadable__ __wur ssize_t
  57. pread64 (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf),
  58. size_t __nbytes, __off64_t __offset)
  59. __fortify_clang_warning_only_if_bos0_lt (__nbytes, __buf,
  60. "pread64 called with bigger length than "
  61. "size of the destination buffer")
  62. {
  63. return __glibc_fortify (pread64, __nbytes, sizeof (char),
  64. __glibc_objsize0 (__buf),
  65. __fd, __buf, __nbytes, __offset);
  66. }
  67. # endif
  68. #endif
  69. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  70. __fortify_function __attribute_overloadable__ __nonnull ((1, 2)) __wur ssize_t
  71. __NTH (readlink (const char *__restrict __path,
  72. __fortify_clang_overload_arg0 (char *, __restrict, __buf),
  73. size_t __len))
  74. __fortify_clang_warning_only_if_bos_lt (__len, __buf,
  75. "readlink called with bigger length "
  76. "than size of destination buffer")
  77. {
  78. return __glibc_fortify (readlink, __len, sizeof (char),
  79. __glibc_objsize (__buf),
  80. __path, __buf, __len);
  81. }
  82. #endif
  83. #ifdef __USE_ATFILE
  84. __fortify_function __attribute_overloadable__ __nonnull ((2, 3)) __wur ssize_t
  85. __NTH (readlinkat (int __fd, const char *__restrict __path,
  86. __fortify_clang_overload_arg0 (char *, __restrict, __buf),
  87. size_t __len))
  88. __fortify_clang_warning_only_if_bos_lt (__len, __buf,
  89. "readlinkat called with bigger length "
  90. "than size of destination buffer")
  91. {
  92. return __glibc_fortify (readlinkat, __len, sizeof (char),
  93. __glibc_objsize (__buf),
  94. __fd, __path, __buf, __len);
  95. }
  96. #endif
  97. __fortify_function __attribute_overloadable__ __wur char *
  98. __NTH (getcwd (__fortify_clang_overload_arg (char *, , __buf), size_t __size))
  99. __fortify_clang_warning_only_if_bos_lt (__size, __buf,
  100. "getcwd called with bigger length "
  101. "than size of destination buffer")
  102. {
  103. return __glibc_fortify (getcwd, __size, sizeof (char),
  104. __glibc_objsize (__buf),
  105. __buf, __size);
  106. }
  107. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  108. __fortify_function __attribute_overloadable__ __nonnull ((1))
  109. __attribute_deprecated__ __wur char *
  110. __NTH (getwd (__fortify_clang_overload_arg (char *,, __buf)))
  111. {
  112. if (__glibc_objsize (__buf) != (size_t) -1)
  113. return __getwd_chk (__buf, __glibc_objsize (__buf));
  114. return __getwd_warn (__buf);
  115. }
  116. #endif
  117. __fortify_function __attribute_overloadable__ size_t
  118. __NTH (confstr (int __name, __fortify_clang_overload_arg (char *, ,__buf),
  119. size_t __len))
  120. __fortify_clang_warning_only_if_bos_lt (__len, __buf,
  121. "confstr called with bigger length than "
  122. "size of destination buffer")
  123. {
  124. return __glibc_fortify (confstr, __len, sizeof (char),
  125. __glibc_objsize (__buf),
  126. __name, __buf, __len);
  127. }
  128. __fortify_function __attribute_overloadable__ int
  129. __NTH (getgroups (int __size,
  130. __fortify_clang_overload_arg (__gid_t *, , __list)))
  131. __fortify_clang_warning_only_if_bos_lt (__size * sizeof (__gid_t), __list,
  132. "getgroups called with bigger group "
  133. "count than what can fit into "
  134. "destination buffer")
  135. {
  136. return __glibc_fortify (getgroups, __size, sizeof (__gid_t),
  137. __glibc_objsize (__list),
  138. __size, __list);
  139. }
  140. __fortify_function __attribute_overloadable__ int
  141. __NTH (ttyname_r (int __fd,
  142. __fortify_clang_overload_arg (char *, ,__buf),
  143. size_t __buflen))
  144. __fortify_clang_warning_only_if_bos_lt (__buflen, __buf,
  145. "ttyname_r called with bigger buflen "
  146. "than size of destination buffer")
  147. {
  148. return __glibc_fortify (ttyname_r, __buflen, sizeof (char),
  149. __glibc_objsize (__buf),
  150. __fd, __buf, __buflen);
  151. }
  152. #ifdef __USE_POSIX199506
  153. __fortify_function __attribute_overloadable__ int
  154. getlogin_r (__fortify_clang_overload_arg (char *, ,__buf), size_t __buflen)
  155. __fortify_clang_warning_only_if_bos_lt (__buflen, __buf,
  156. "getlogin_r called with bigger buflen "
  157. "than size of destination buffer")
  158. {
  159. return __glibc_fortify (getlogin_r, __buflen, sizeof (char),
  160. __glibc_objsize (__buf),
  161. __buf, __buflen);
  162. }
  163. #endif
  164. #if defined __USE_MISC || defined __USE_UNIX98
  165. __fortify_function __attribute_overloadable__ int
  166. __NTH (gethostname (__fortify_clang_overload_arg (char *, ,__buf),
  167. size_t __buflen))
  168. __fortify_clang_warning_only_if_bos_lt (__buflen, __buf,
  169. "gethostname called with bigger buflen "
  170. "than size of destination buffer")
  171. {
  172. return __glibc_fortify (gethostname, __buflen, sizeof (char),
  173. __glibc_objsize (__buf),
  174. __buf, __buflen);
  175. }
  176. #endif
  177. #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_UNIX98)
  178. __fortify_function __attribute_overloadable__ int
  179. __NTH (getdomainname (__fortify_clang_overload_arg (char *, ,__buf),
  180. size_t __buflen))
  181. __fortify_clang_warning_only_if_bos_lt (__buflen, __buf,
  182. "getdomainname called with bigger "
  183. "buflen than size of destination buffer")
  184. {
  185. return __glibc_fortify (getdomainname, __buflen, sizeof (char),
  186. __glibc_objsize (__buf),
  187. __buf, __buflen);
  188. }
  189. #endif