unistd.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /* Checking macros for unistd functions.
  2. Copyright (C) 2005, 2006, 2007, 2008 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 _UNISTD_H
  17. # error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
  18. #endif
  19. extern ssize_t __read_chk (int __fd, void *__buf, size_t __nbytes,
  20. size_t __buflen) __wur;
  21. extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
  22. size_t __nbytes), read) __wur;
  23. extern ssize_t __REDIRECT (__read_chk_warn,
  24. (int __fd, void *__buf, size_t __nbytes,
  25. size_t __buflen), __read_chk)
  26. __wur __warnattr ("read called with bigger length than size of "
  27. "the destination buffer");
  28. __extern_always_inline __wur ssize_t
  29. read (int __fd, void *__buf, size_t __nbytes)
  30. {
  31. if (__bos0 (__buf) != (size_t) -1)
  32. {
  33. if (!__builtin_constant_p (__nbytes))
  34. return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf));
  35. if (__nbytes > __bos0 (__buf))
  36. return __read_chk_warn (__fd, __buf, __nbytes, __bos0 (__buf));
  37. }
  38. return __read_alias (__fd, __buf, __nbytes);
  39. }
  40. #ifdef __USE_UNIX98
  41. extern ssize_t __pread_chk (int __fd, void *__buf, size_t __nbytes,
  42. __off_t __offset, size_t __bufsize) __wur;
  43. extern ssize_t __pread64_chk (int __fd, void *__buf, size_t __nbytes,
  44. __off64_t __offset, size_t __bufsize) __wur;
  45. extern ssize_t __REDIRECT (__pread_alias,
  46. (int __fd, void *__buf, size_t __nbytes,
  47. __off_t __offset), pread) __wur;
  48. extern ssize_t __REDIRECT (__pread64_alias,
  49. (int __fd, void *__buf, size_t __nbytes,
  50. __off64_t __offset), pread64) __wur;
  51. extern ssize_t __REDIRECT (__pread_chk_warn,
  52. (int __fd, void *__buf, size_t __nbytes,
  53. __off_t __offset, size_t __bufsize), __pread_chk)
  54. __wur __warnattr ("pread called with bigger length than size of "
  55. "the destination buffer");
  56. extern ssize_t __REDIRECT (__pread64_chk_warn,
  57. (int __fd, void *__buf, size_t __nbytes,
  58. __off64_t __offset, size_t __bufsize),
  59. __pread64_chk)
  60. __wur __warnattr ("pread64 called with bigger length than size of "
  61. "the destination buffer");
  62. # ifndef __USE_FILE_OFFSET64
  63. __extern_always_inline __wur ssize_t
  64. pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
  65. {
  66. if (__bos0 (__buf) != (size_t) -1)
  67. {
  68. if (!__builtin_constant_p (__nbytes))
  69. return __pread_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
  70. if ( __nbytes > __bos0 (__buf))
  71. return __pread_chk_warn (__fd, __buf, __nbytes, __offset,
  72. __bos0 (__buf));
  73. }
  74. return __pread_alias (__fd, __buf, __nbytes, __offset);
  75. }
  76. # else
  77. __extern_always_inline __wur ssize_t
  78. pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
  79. {
  80. if (__bos0 (__buf) != (size_t) -1)
  81. {
  82. if (!__builtin_constant_p (__nbytes))
  83. return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
  84. if ( __nbytes > __bos0 (__buf))
  85. return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
  86. __bos0 (__buf));
  87. }
  88. return __pread64_alias (__fd, __buf, __nbytes, __offset);
  89. }
  90. # endif
  91. # ifdef __USE_LARGEFILE64
  92. __extern_always_inline __wur ssize_t
  93. pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
  94. {
  95. if (__bos0 (__buf) != (size_t) -1)
  96. {
  97. if (!__builtin_constant_p (__nbytes))
  98. return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
  99. if ( __nbytes > __bos0 (__buf))
  100. return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
  101. __bos0 (__buf));
  102. }
  103. return __pread64_alias (__fd, __buf, __nbytes, __offset);
  104. }
  105. # endif
  106. #endif
  107. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
  108. extern ssize_t __readlink_chk (__const char *__restrict __path,
  109. char *__restrict __buf, size_t __len,
  110. size_t __buflen)
  111. __THROW __nonnull ((1, 2)) __wur;
  112. extern ssize_t __REDIRECT_NTH (__readlink_alias,
  113. (__const char *__restrict __path,
  114. char *__restrict __buf, size_t __len), readlink)
  115. __nonnull ((1, 2)) __wur;
  116. extern ssize_t __REDIRECT_NTH (__readlink_chk_warn,
  117. (__const char *__restrict __path,
  118. char *__restrict __buf, size_t __len,
  119. size_t __buflen), __readlink_chk)
  120. __nonnull ((1, 2)) __wur __warnattr ("readlink called with bigger length "
  121. "than size of destination buffer");
  122. __extern_always_inline __nonnull ((1, 2)) __wur ssize_t
  123. __NTH (readlink (__const char *__restrict __path, char *__restrict __buf,
  124. size_t __len))
  125. {
  126. if (__bos (__buf) != (size_t) -1)
  127. {
  128. if (!__builtin_constant_p (__len))
  129. return __readlink_chk (__path, __buf, __len, __bos (__buf));
  130. if ( __len > __bos (__buf))
  131. return __readlink_chk_warn (__path, __buf, __len, __bos (__buf));
  132. }
  133. return __readlink_alias (__path, __buf, __len);
  134. }
  135. #endif
  136. #ifdef __USE_ATFILE
  137. extern ssize_t __readlinkat_chk (int __fd, __const char *__restrict __path,
  138. char *__restrict __buf, size_t __len,
  139. size_t __buflen)
  140. __THROW __nonnull ((2, 3)) __wur;
  141. extern ssize_t __REDIRECT_NTH (__readlinkat_alias,
  142. (int __fd, __const char *__restrict __path,
  143. char *__restrict __buf, size_t __len),
  144. readlinkat)
  145. __nonnull ((2, 3)) __wur;
  146. extern ssize_t __REDIRECT_NTH (__readlinkat_chk_warn,
  147. (int __fd, __const char *__restrict __path,
  148. char *__restrict __buf, size_t __len,
  149. size_t __buflen), __readlinkat_chk)
  150. __nonnull ((2, 3)) __wur __warnattr ("readlinkat called with bigger "
  151. "length than size of destination "
  152. "buffer");
  153. __extern_always_inline __nonnull ((2, 3)) __wur ssize_t
  154. __NTH (readlinkat (int __fd, __const char *__restrict __path,
  155. char *__restrict __buf, size_t __len))
  156. {
  157. if (__bos (__buf) != (size_t) -1)
  158. {
  159. if (!__builtin_constant_p (__len))
  160. return __readlinkat_chk (__fd, __path, __buf, __len, __bos (__buf));
  161. if (__len > __bos (__buf))
  162. return __readlinkat_chk_warn (__fd, __path, __buf, __len,
  163. __bos (__buf));
  164. }
  165. return __readlinkat_alias (__fd, __path, __buf, __len);
  166. }
  167. #endif
  168. extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen)
  169. __THROW __wur;
  170. extern char *__REDIRECT_NTH (__getcwd_alias,
  171. (char *__buf, size_t __size), getcwd) __wur;
  172. extern char *__REDIRECT_NTH (__getcwd_chk_warn,
  173. (char *__buf, size_t __size, size_t __buflen),
  174. __getcwd_chk)
  175. __wur __warnattr ("getcwd caller with bigger length than size of "
  176. "destination buffer");
  177. __extern_always_inline __wur char *
  178. __NTH (getcwd (char *__buf, size_t __size))
  179. {
  180. if (__bos (__buf) != (size_t) -1)
  181. {
  182. if (!__builtin_constant_p (__size))
  183. return __getcwd_chk (__buf, __size, __bos (__buf));
  184. if (__size > __bos (__buf))
  185. return __getcwd_chk_warn (__buf, __size, __bos (__buf));
  186. }
  187. return __getcwd_alias (__buf, __size);
  188. }
  189. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  190. extern char *__getwd_chk (char *__buf, size_t buflen)
  191. __THROW __nonnull ((1)) __wur;
  192. extern char *__REDIRECT_NTH (__getwd_warn, (char *__buf), getwd)
  193. __nonnull ((1)) __wur __warnattr ("please use getcwd instead, as getwd "
  194. "doesn't specify buffer size");
  195. __extern_always_inline __nonnull ((1)) __attribute_deprecated__ __wur char *
  196. __NTH (getwd (char *__buf))
  197. {
  198. if (__bos (__buf) != (size_t) -1)
  199. return __getwd_chk (__buf, __bos (__buf));
  200. return __getwd_warn (__buf);
  201. }
  202. #endif
  203. extern size_t __confstr_chk (int __name, char *__buf, size_t __len,
  204. size_t __buflen) __THROW;
  205. extern size_t __REDIRECT_NTH (__confstr_alias, (int __name, char *__buf,
  206. size_t __len), confstr);
  207. extern size_t __REDIRECT_NTH (__confstr_chk_warn,
  208. (int __name, char *__buf, size_t __len,
  209. size_t __buflen), __confstr_chk)
  210. __warnattr ("confstr called with bigger length than size of destination "
  211. "buffer");
  212. __extern_always_inline size_t
  213. __NTH (confstr (int __name, char *__buf, size_t __len))
  214. {
  215. if (__bos (__buf) != (size_t) -1)
  216. {
  217. if (!__builtin_constant_p (__len))
  218. return __confstr_chk (__name, __buf, __len, __bos (__buf));
  219. if (__bos (__buf) < __len)
  220. return __confstr_chk_warn (__name, __buf, __len, __bos (__buf));
  221. }
  222. return __confstr_alias (__name, __buf, __len);
  223. }
  224. extern int __getgroups_chk (int __size, __gid_t __list[], size_t __listlen)
  225. __THROW __wur;
  226. extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]),
  227. getgroups) __wur;
  228. extern int __REDIRECT_NTH (__getgroups_chk_warn,
  229. (int __size, __gid_t __list[], size_t __listlen),
  230. __getgroups_chk)
  231. __wur __warnattr ("getgroups called with bigger group count than what "
  232. "can fit into destination buffer");
  233. __extern_always_inline int
  234. __NTH (getgroups (int __size, __gid_t __list[]))
  235. {
  236. if (__bos (__list) != (size_t) -1)
  237. {
  238. if (!__builtin_constant_p (__size) || __size < 0)
  239. return __getgroups_chk (__size, __list, __bos (__list));
  240. if (__size * sizeof (__gid_t) > __bos (__list))
  241. return __getgroups_chk_warn (__size, __list, __bos (__list));
  242. }
  243. return __getgroups_alias (__size, __list);
  244. }
  245. extern int __ttyname_r_chk (int __fd, char *__buf, size_t __buflen,
  246. size_t __nreal) __THROW __nonnull ((2));
  247. extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
  248. size_t __buflen), ttyname_r)
  249. __nonnull ((2));
  250. extern int __REDIRECT_NTH (__ttyname_r_chk_warn,
  251. (int __fd, char *__buf, size_t __buflen,
  252. size_t __nreal), __ttyname_r_chk)
  253. __nonnull ((2)) __warnattr ("ttyname_r called with bigger buflen than "
  254. "size of destination buffer");
  255. __extern_always_inline int
  256. __NTH (ttyname_r (int __fd, char *__buf, size_t __buflen))
  257. {
  258. if (__bos (__buf) != (size_t) -1)
  259. {
  260. if (!__builtin_constant_p (__buflen))
  261. return __ttyname_r_chk (__fd, __buf, __buflen, __bos (__buf));
  262. if (__buflen > __bos (__buf))
  263. return __ttyname_r_chk_warn (__fd, __buf, __buflen, __bos (__buf));
  264. }
  265. return __ttyname_r_alias (__fd, __buf, __buflen);
  266. }
  267. #if defined __USE_REENTRANT || defined __USE_POSIX199506
  268. extern int __getlogin_r_chk (char *__buf, size_t __buflen, size_t __nreal)
  269. __nonnull ((1));
  270. extern int __REDIRECT (__getlogin_r_alias, (char *__buf, size_t __buflen),
  271. getlogin_r) __nonnull ((1));
  272. extern int __REDIRECT (__getlogin_r_chk_warn,
  273. (char *__buf, size_t __buflen, size_t __nreal),
  274. __getlogin_r_chk)
  275. __nonnull ((1)) __warnattr ("getlogin_r called with bigger buflen than "
  276. "size of destination buffer");
  277. __extern_always_inline int
  278. getlogin_r (char *__buf, size_t __buflen)
  279. {
  280. if (__bos (__buf) != (size_t) -1)
  281. {
  282. if (!__builtin_constant_p (__buflen))
  283. return __getlogin_r_chk (__buf, __buflen, __bos (__buf));
  284. if (__buflen > __bos (__buf))
  285. return __getlogin_r_chk_warn (__buf, __buflen, __bos (__buf));
  286. }
  287. return __getlogin_r_alias (__buf, __buflen);
  288. }
  289. #endif
  290. #if defined __USE_BSD || defined __USE_UNIX98
  291. extern int __gethostname_chk (char *__buf, size_t __buflen, size_t __nreal)
  292. __THROW __nonnull ((1));
  293. extern int __REDIRECT_NTH (__gethostname_alias, (char *__buf, size_t __buflen),
  294. gethostname) __nonnull ((1));
  295. extern int __REDIRECT_NTH (__gethostname_chk_warn,
  296. (char *__buf, size_t __buflen, size_t __nreal),
  297. __gethostname_chk)
  298. __nonnull ((1)) __warnattr ("gethostname called with bigger buflen than "
  299. "size of destination buffer");
  300. __extern_always_inline int
  301. __NTH (gethostname (char *__buf, size_t __buflen))
  302. {
  303. if (__bos (__buf) != (size_t) -1)
  304. {
  305. if (!__builtin_constant_p (__buflen))
  306. return __gethostname_chk (__buf, __buflen, __bos (__buf));
  307. if (__buflen > __bos (__buf))
  308. return __gethostname_chk_warn (__buf, __buflen, __bos (__buf));
  309. }
  310. return __gethostname_alias (__buf, __buflen);
  311. }
  312. #endif
  313. #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
  314. extern int __getdomainname_chk (char *__buf, size_t __buflen, size_t __nreal)
  315. __THROW __nonnull ((1)) __wur;
  316. extern int __REDIRECT_NTH (__getdomainname_alias, (char *__buf,
  317. size_t __buflen),
  318. getdomainname) __nonnull ((1)) __wur;
  319. extern int __REDIRECT_NTH (__getdomainname_chk_warn,
  320. (char *__buf, size_t __buflen, size_t __nreal),
  321. __getdomainname_chk)
  322. __nonnull ((1)) __wur __warnattr ("getdomainname called with bigger "
  323. "buflen than size of destination "
  324. "buffer");
  325. __extern_always_inline int
  326. __NTH (getdomainname (char *__buf, size_t __buflen))
  327. {
  328. if (__bos (__buf) != (size_t) -1)
  329. {
  330. if (!__builtin_constant_p (__buflen))
  331. return __getdomainname_chk (__buf, __buflen, __bos (__buf));
  332. if (__buflen > __bos (__buf))
  333. return __getdomainname_chk_warn (__buf, __buflen, __bos (__buf));
  334. }
  335. return __getdomainname_alias (__buf, __buflen);
  336. }
  337. #endif