unistd.h 7.9 KB

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