Branch data Line data Source code
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 : :
5 : : The GNU C Library is free software; you can redistribute it and/or
6 : : modify it under the terms of the GNU Lesser General Public
7 : : License as published by the Free Software Foundation; either
8 : : version 2.1 of the License, or (at your option) any later version.
9 : :
10 : : The GNU C Library is distributed in the hope that it will be useful,
11 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : : Lesser General Public License for more details.
14 : :
15 : : You should have received a copy of the GNU Lesser General Public
16 : : License along with the GNU C Library; if not, write to the Free
17 : : Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 : : 02111-1307 USA. */
19 : :
20 : : #ifndef _UNISTD_H
21 : : # error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
22 : : #endif
23 : :
24 : : extern ssize_t __read_chk (int __fd, void *__buf, size_t __nbytes,
25 : : size_t __buflen) __wur;
26 : : extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
27 : : size_t __nbytes), read) __wur;
28 : : extern ssize_t __REDIRECT (__read_chk_warn,
29 : : (int __fd, void *__buf, size_t __nbytes,
30 : : size_t __buflen), __read_chk)
31 : : __wur __warnattr ("read called with bigger length than size of "
32 : : "the destination buffer");
33 : :
34 : : __extern_always_inline __wur ssize_t
35 : : read (int __fd, void *__buf, size_t __nbytes)
36 : : {
37 [ - + ]: 23 : if (__bos0 (__buf) != (size_t) -1)
38 : : {
39 [ # # ]: 0 : if (!__builtin_constant_p (__nbytes))
40 : 0 : return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf));
41 : :
42 [ # # ]: 0 : if (__nbytes > __bos0 (__buf))
43 : 0 : return __read_chk_warn (__fd, __buf, __nbytes, __bos0 (__buf));
44 : : }
45 : 23 : return __read_alias (__fd, __buf, __nbytes);
46 : : }
47 : :
48 : : #ifdef __USE_UNIX98
49 : : extern ssize_t __pread_chk (int __fd, void *__buf, size_t __nbytes,
50 : : __off_t __offset, size_t __bufsize) __wur;
51 : : extern ssize_t __pread64_chk (int __fd, void *__buf, size_t __nbytes,
52 : : __off64_t __offset, size_t __bufsize) __wur;
53 : : extern ssize_t __REDIRECT (__pread_alias,
54 : : (int __fd, void *__buf, size_t __nbytes,
55 : : __off_t __offset), pread) __wur;
56 : : extern ssize_t __REDIRECT (__pread64_alias,
57 : : (int __fd, void *__buf, size_t __nbytes,
58 : : __off64_t __offset), pread64) __wur;
59 : : extern ssize_t __REDIRECT (__pread_chk_warn,
60 : : (int __fd, void *__buf, size_t __nbytes,
61 : : __off_t __offset, size_t __bufsize), __pread_chk)
62 : : __wur __warnattr ("pread called with bigger length than size of "
63 : : "the destination buffer");
64 : : extern ssize_t __REDIRECT (__pread64_chk_warn,
65 : : (int __fd, void *__buf, size_t __nbytes,
66 : : __off64_t __offset, size_t __bufsize),
67 : : __pread64_chk)
68 : : __wur __warnattr ("pread64 called with bigger length than size of "
69 : : "the destination buffer");
70 : :
71 : : # ifndef __USE_FILE_OFFSET64
72 : : __extern_always_inline __wur ssize_t
73 : : pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
74 : : {
75 : : if (__bos0 (__buf) != (size_t) -1)
76 : : {
77 : : if (!__builtin_constant_p (__nbytes))
78 : : return __pread_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
79 : :
80 : : if ( __nbytes > __bos0 (__buf))
81 : : return __pread_chk_warn (__fd, __buf, __nbytes, __offset,
82 : : __bos0 (__buf));
83 : : }
84 : : return __pread_alias (__fd, __buf, __nbytes, __offset);
85 : : }
86 : : # else
87 : : __extern_always_inline __wur ssize_t
88 : : pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
89 : : {
90 : : if (__bos0 (__buf) != (size_t) -1)
91 : : {
92 : : if (!__builtin_constant_p (__nbytes))
93 : : return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
94 : :
95 : : if ( __nbytes > __bos0 (__buf))
96 : : return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
97 : : __bos0 (__buf));
98 : : }
99 : :
100 : : return __pread64_alias (__fd, __buf, __nbytes, __offset);
101 : : }
102 : : # endif
103 : :
104 : : # ifdef __USE_LARGEFILE64
105 : : __extern_always_inline __wur ssize_t
106 : : pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
107 : : {
108 : : if (__bos0 (__buf) != (size_t) -1)
109 : : {
110 : : if (!__builtin_constant_p (__nbytes))
111 : : return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
112 : :
113 : : if ( __nbytes > __bos0 (__buf))
114 : : return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
115 : : __bos0 (__buf));
116 : : }
117 : :
118 : : return __pread64_alias (__fd, __buf, __nbytes, __offset);
119 : : }
120 : : # endif
121 : : #endif
122 : :
123 : : #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
124 : : extern ssize_t __readlink_chk (__const char *__restrict __path,
125 : : char *__restrict __buf, size_t __len,
126 : : size_t __buflen)
127 : : __THROW __nonnull ((1, 2)) __wur;
128 : : extern ssize_t __REDIRECT_NTH (__readlink_alias,
129 : : (__const char *__restrict __path,
130 : : char *__restrict __buf, size_t __len), readlink)
131 : : __nonnull ((1, 2)) __wur;
132 : : extern ssize_t __REDIRECT_NTH (__readlink_chk_warn,
133 : : (__const char *__restrict __path,
134 : : char *__restrict __buf, size_t __len,
135 : : size_t __buflen), __readlink_chk)
136 : : __nonnull ((1, 2)) __wur __warnattr ("readlink called with bigger length "
137 : : "than size of destination buffer");
138 : :
139 : : __extern_always_inline __nonnull ((1, 2)) __wur ssize_t
140 : : __NTH (readlink (__const char *__restrict __path, char *__restrict __buf,
141 : : size_t __len))
142 : : {
143 [ - + ]: 21 : if (__bos (__buf) != (size_t) -1)
144 : : {
145 [ # # ]: 0 : if (!__builtin_constant_p (__len))
146 : 0 : return __readlink_chk (__path, __buf, __len, __bos (__buf));
147 : :
148 [ # # ]: 0 : if ( __len > __bos (__buf))
149 : 0 : return __readlink_chk_warn (__path, __buf, __len, __bos (__buf));
150 : : }
151 : 21 : return __readlink_alias (__path, __buf, __len);
152 : : }
153 : : #endif
154 : :
155 : : #ifdef __USE_ATFILE
156 : : extern ssize_t __readlinkat_chk (int __fd, __const char *__restrict __path,
157 : : char *__restrict __buf, size_t __len,
158 : : size_t __buflen)
159 : : __THROW __nonnull ((2, 3)) __wur;
160 : : extern ssize_t __REDIRECT_NTH (__readlinkat_alias,
161 : : (int __fd, __const char *__restrict __path,
162 : : char *__restrict __buf, size_t __len),
163 : : readlinkat)
164 : : __nonnull ((2, 3)) __wur;
165 : : extern ssize_t __REDIRECT_NTH (__readlinkat_chk_warn,
166 : : (int __fd, __const char *__restrict __path,
167 : : char *__restrict __buf, size_t __len,
168 : : size_t __buflen), __readlinkat_chk)
169 : : __nonnull ((2, 3)) __wur __warnattr ("readlinkat called with bigger "
170 : : "length than size of destination "
171 : : "buffer");
172 : :
173 : : __extern_always_inline __nonnull ((2, 3)) __wur ssize_t
174 : : __NTH (readlinkat (int __fd, __const char *__restrict __path,
175 : : char *__restrict __buf, size_t __len))
176 : : {
177 : : if (__bos (__buf) != (size_t) -1)
178 : : {
179 : : if (!__builtin_constant_p (__len))
180 : : return __readlinkat_chk (__fd, __path, __buf, __len, __bos (__buf));
181 : :
182 : : if (__len > __bos (__buf))
183 : : return __readlinkat_chk_warn (__fd, __path, __buf, __len,
184 : : __bos (__buf));
185 : : }
186 : : return __readlinkat_alias (__fd, __path, __buf, __len);
187 : : }
188 : : #endif
189 : :
190 : : extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen)
191 : : __THROW __wur;
192 : : extern char *__REDIRECT_NTH (__getcwd_alias,
193 : : (char *__buf, size_t __size), getcwd) __wur;
194 : : extern char *__REDIRECT_NTH (__getcwd_chk_warn,
195 : : (char *__buf, size_t __size, size_t __buflen),
196 : : __getcwd_chk)
197 : : __wur __warnattr ("getcwd caller with bigger length than size of "
198 : : "destination buffer");
199 : :
200 : : __extern_always_inline __wur char *
201 : : __NTH (getcwd (char *__buf, size_t __size))
202 : : {
203 [ # # ]: 0 : if (__bos (__buf) != (size_t) -1)
204 : : {
205 [ # # ]: 0 : if (!__builtin_constant_p (__size))
206 : 0 : return __getcwd_chk (__buf, __size, __bos (__buf));
207 : :
208 [ # # ]: 0 : if (__size > __bos (__buf))
209 : 0 : return __getcwd_chk_warn (__buf, __size, __bos (__buf));
210 : : }
211 : 0 : return __getcwd_alias (__buf, __size);
212 : : }
213 : :
214 : : #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
215 : : extern char *__getwd_chk (char *__buf, size_t buflen)
216 : : __THROW __nonnull ((1)) __wur;
217 : : extern char *__REDIRECT_NTH (__getwd_warn, (char *__buf), getwd)
218 : : __nonnull ((1)) __wur __warnattr ("please use getcwd instead, as getwd "
219 : : "doesn't specify buffer size");
220 : :
221 : : __extern_always_inline __nonnull ((1)) __attribute_deprecated__ __wur char *
222 : : __NTH (getwd (char *__buf))
223 : : {
224 : : if (__bos (__buf) != (size_t) -1)
225 : : return __getwd_chk (__buf, __bos (__buf));
226 : : return __getwd_warn (__buf);
227 : : }
228 : : #endif
229 : :
230 : : extern size_t __confstr_chk (int __name, char *__buf, size_t __len,
231 : : size_t __buflen) __THROW;
232 : : extern size_t __REDIRECT_NTH (__confstr_alias, (int __name, char *__buf,
233 : : size_t __len), confstr);
234 : : extern size_t __REDIRECT_NTH (__confstr_chk_warn,
235 : : (int __name, char *__buf, size_t __len,
236 : : size_t __buflen), __confstr_chk)
237 : : __warnattr ("confstr called with bigger length than size of destination "
238 : : "buffer");
239 : :
240 : : __extern_always_inline size_t
241 : : __NTH (confstr (int __name, char *__buf, size_t __len))
242 : : {
243 : : if (__bos (__buf) != (size_t) -1)
244 : : {
245 : : if (!__builtin_constant_p (__len))
246 : : return __confstr_chk (__name, __buf, __len, __bos (__buf));
247 : :
248 : : if (__bos (__buf) < __len)
249 : : return __confstr_chk_warn (__name, __buf, __len, __bos (__buf));
250 : : }
251 : : return __confstr_alias (__name, __buf, __len);
252 : : }
253 : :
254 : :
255 : : extern int __getgroups_chk (int __size, __gid_t __list[], size_t __listlen)
256 : : __THROW __wur;
257 : : extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]),
258 : : getgroups) __wur;
259 : : extern int __REDIRECT_NTH (__getgroups_chk_warn,
260 : : (int __size, __gid_t __list[], size_t __listlen),
261 : : __getgroups_chk)
262 : : __wur __warnattr ("getgroups called with bigger group count than what "
263 : : "can fit into destination buffer");
264 : :
265 : : __extern_always_inline int
266 : : __NTH (getgroups (int __size, __gid_t __list[]))
267 : : {
268 [ # # ]: 0 : if (__bos (__list) != (size_t) -1)
269 : : {
270 [ # # ]: 0 : if (!__builtin_constant_p (__size) || __size < 0)
271 : 0 : return __getgroups_chk (__size, __list, __bos (__list));
272 : :
273 [ # # ]: 0 : if (__size * sizeof (__gid_t) > __bos (__list))
274 : 0 : return __getgroups_chk_warn (__size, __list, __bos (__list));
275 : : }
276 : 0 : return __getgroups_alias (__size, __list);
277 : : }
278 : :
279 : :
280 : : extern int __ttyname_r_chk (int __fd, char *__buf, size_t __buflen,
281 : : size_t __nreal) __THROW __nonnull ((2));
282 : : extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
283 : : size_t __buflen), ttyname_r)
284 : : __nonnull ((2));
285 : : extern int __REDIRECT_NTH (__ttyname_r_chk_warn,
286 : : (int __fd, char *__buf, size_t __buflen,
287 : : size_t __nreal), __ttyname_r_chk)
288 : : __nonnull ((2)) __warnattr ("ttyname_r called with bigger buflen than "
289 : : "size of destination buffer");
290 : :
291 : : __extern_always_inline int
292 : : __NTH (ttyname_r (int __fd, char *__buf, size_t __buflen))
293 : : {
294 : : if (__bos (__buf) != (size_t) -1)
295 : : {
296 : : if (!__builtin_constant_p (__buflen))
297 : : return __ttyname_r_chk (__fd, __buf, __buflen, __bos (__buf));
298 : :
299 : : if (__buflen > __bos (__buf))
300 : : return __ttyname_r_chk_warn (__fd, __buf, __buflen, __bos (__buf));
301 : : }
302 : : return __ttyname_r_alias (__fd, __buf, __buflen);
303 : : }
304 : :
305 : :
306 : : #if defined __USE_REENTRANT || defined __USE_POSIX199506
307 : : extern int __getlogin_r_chk (char *__buf, size_t __buflen, size_t __nreal)
308 : : __nonnull ((1));
309 : : extern int __REDIRECT (__getlogin_r_alias, (char *__buf, size_t __buflen),
310 : : getlogin_r) __nonnull ((1));
311 : : extern int __REDIRECT (__getlogin_r_chk_warn,
312 : : (char *__buf, size_t __buflen, size_t __nreal),
313 : : __getlogin_r_chk)
314 : : __nonnull ((1)) __warnattr ("getlogin_r called with bigger buflen than "
315 : : "size of destination buffer");
316 : :
317 : : __extern_always_inline int
318 : : getlogin_r (char *__buf, size_t __buflen)
319 : : {
320 : : if (__bos (__buf) != (size_t) -1)
321 : : {
322 : : if (!__builtin_constant_p (__buflen))
323 : : return __getlogin_r_chk (__buf, __buflen, __bos (__buf));
324 : :
325 : : if (__buflen > __bos (__buf))
326 : : return __getlogin_r_chk_warn (__buf, __buflen, __bos (__buf));
327 : : }
328 : : return __getlogin_r_alias (__buf, __buflen);
329 : : }
330 : : #endif
331 : :
332 : :
333 : : #if defined __USE_BSD || defined __USE_UNIX98
334 : : extern int __gethostname_chk (char *__buf, size_t __buflen, size_t __nreal)
335 : : __THROW __nonnull ((1));
336 : : extern int __REDIRECT_NTH (__gethostname_alias, (char *__buf, size_t __buflen),
337 : : gethostname) __nonnull ((1));
338 : : extern int __REDIRECT_NTH (__gethostname_chk_warn,
339 : : (char *__buf, size_t __buflen, size_t __nreal),
340 : : __gethostname_chk)
341 : : __nonnull ((1)) __warnattr ("gethostname called with bigger buflen than "
342 : : "size of destination buffer");
343 : :
344 : : __extern_always_inline int
345 : : __NTH (gethostname (char *__buf, size_t __buflen))
346 : : {
347 [ # # ]: 0 : if (__bos (__buf) != (size_t) -1)
348 : : {
349 [ # # ]: 0 : if (!__builtin_constant_p (__buflen))
350 : 0 : return __gethostname_chk (__buf, __buflen, __bos (__buf));
351 : :
352 [ # # ]: 0 : if (__buflen > __bos (__buf))
353 : 0 : return __gethostname_chk_warn (__buf, __buflen, __bos (__buf));
354 : : }
355 : 0 : return __gethostname_alias (__buf, __buflen);
356 : : }
357 : : #endif
358 : :
359 : :
360 : : #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
361 : : extern int __getdomainname_chk (char *__buf, size_t __buflen, size_t __nreal)
362 : : __THROW __nonnull ((1)) __wur;
363 : : extern int __REDIRECT_NTH (__getdomainname_alias, (char *__buf,
364 : : size_t __buflen),
365 : : getdomainname) __nonnull ((1)) __wur;
366 : : extern int __REDIRECT_NTH (__getdomainname_chk_warn,
367 : : (char *__buf, size_t __buflen, size_t __nreal),
368 : : __getdomainname_chk)
369 : : __nonnull ((1)) __wur __warnattr ("getdomainname called with bigger "
370 : : "buflen than size of destination "
371 : : "buffer");
372 : :
373 : : __extern_always_inline int
374 : : __NTH (getdomainname (char *__buf, size_t __buflen))
375 : : {
376 : : if (__bos (__buf) != (size_t) -1)
377 : : {
378 : : if (!__builtin_constant_p (__buflen))
379 : : return __getdomainname_chk (__buf, __buflen, __bos (__buf));
380 : :
381 : : if (__buflen > __bos (__buf))
382 : : return __getdomainname_chk_warn (__buf, __buflen, __bos (__buf));
383 : : }
384 : : return __getdomainname_alias (__buf, __buflen);
385 : : }
386 : : #endif
|