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.
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.
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.
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
21 # error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
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");
34 __extern_always_inline __wur ssize_t
35 read (int __fd
, void *__buf
, size_t __nbytes
)
37 if (__bos0 (__buf
) != (size_t) -1)
39 if (!__builtin_constant_p (__nbytes
))
40 return __read_chk (__fd
, __buf
, __nbytes
, __bos0 (__buf
));
42 if (__nbytes
> __bos0 (__buf
))
43 return __read_chk_warn (__fd
, __buf
, __nbytes
, __bos0 (__buf
));
45 return __read_alias (__fd
, __buf
, __nbytes
);
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
),
68 __wur
__warnattr ("pread64 called with bigger length than size of "
69 "the destination buffer");
71 # ifndef __USE_FILE_OFFSET64
72 __extern_always_inline __wur ssize_t
73 pread (int __fd
, void *__buf
, size_t __nbytes
, __off_t __offset
)
75 if (__bos0 (__buf
) != (size_t) -1)
77 if (!__builtin_constant_p (__nbytes
))
78 return __pread_chk (__fd
, __buf
, __nbytes
, __offset
, __bos0 (__buf
));
80 if ( __nbytes
> __bos0 (__buf
))
81 return __pread_chk_warn (__fd
, __buf
, __nbytes
, __offset
,
84 return __pread_alias (__fd
, __buf
, __nbytes
, __offset
);
87 __extern_always_inline __wur ssize_t
88 pread (int __fd
, void *__buf
, size_t __nbytes
, __off64_t __offset
)
90 if (__bos0 (__buf
) != (size_t) -1)
92 if (!__builtin_constant_p (__nbytes
))
93 return __pread64_chk (__fd
, __buf
, __nbytes
, __offset
, __bos0 (__buf
));
95 if ( __nbytes
> __bos0 (__buf
))
96 return __pread64_chk_warn (__fd
, __buf
, __nbytes
, __offset
,
100 return __pread64_alias (__fd
, __buf
, __nbytes
, __offset
);
104 # ifdef __USE_LARGEFILE64
105 __extern_always_inline __wur ssize_t
106 pread64 (int __fd
, void *__buf
, size_t __nbytes
, __off64_t __offset
)
108 if (__bos0 (__buf
) != (size_t) -1)
110 if (!__builtin_constant_p (__nbytes
))
111 return __pread64_chk (__fd
, __buf
, __nbytes
, __offset
, __bos0 (__buf
));
113 if ( __nbytes
> __bos0 (__buf
))
114 return __pread64_chk_warn (__fd
, __buf
, __nbytes
, __offset
,
118 return __pread64_alias (__fd
, __buf
, __nbytes
, __offset
);
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
,
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");
139 __extern_always_inline
__nonnull ((1, 2)) __wur ssize_t
140 __NTH (readlink (__const
char *__restrict __path
, char *__restrict __buf
,
143 if (__bos (__buf
) != (size_t) -1)
145 if (!__builtin_constant_p (__len
))
146 return __readlink_chk (__path
, __buf
, __len
, __bos (__buf
));
148 if ( __len
> __bos (__buf
))
149 return __readlink_chk_warn (__path
, __buf
, __len
, __bos (__buf
));
151 return __readlink_alias (__path
, __buf
, __len
);
156 extern ssize_t
__readlinkat_chk (int __fd
, __const
char *__restrict __path
,
157 char *__restrict __buf
, size_t __len
,
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
),
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 "
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
))
177 if (__bos (__buf
) != (size_t) -1)
179 if (!__builtin_constant_p (__len
))
180 return __readlinkat_chk (__fd
, __path
, __buf
, __len
, __bos (__buf
));
182 if (__len
> __bos (__buf
))
183 return __readlinkat_chk_warn (__fd
, __path
, __buf
, __len
,
186 return __readlinkat_alias (__fd
, __path
, __buf
, __len
);
190 extern char *__getcwd_chk (char *__buf
, size_t __size
, size_t __buflen
)
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
),
197 __wur
__warnattr ("getcwd caller with bigger length than size of "
198 "destination buffer");
200 __extern_always_inline __wur
char *
201 __NTH (getcwd (char *__buf
, size_t __size
))
203 if (__bos (__buf
) != (size_t) -1)
205 if (!__builtin_constant_p (__size
))
206 return __getcwd_chk (__buf
, __size
, __bos (__buf
));
208 if (__size
> __bos (__buf
))
209 return __getcwd_chk_warn (__buf
, __size
, __bos (__buf
));
211 return __getcwd_alias (__buf
, __size
);
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");
221 __extern_always_inline
__nonnull ((1)) __attribute_deprecated__ __wur
char *
222 __NTH (getwd (char *__buf
))
224 if (__bos (__buf
) != (size_t) -1)
225 return __getwd_chk (__buf
, __bos (__buf
));
226 return __getwd_warn (__buf
);
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 "
240 __extern_always_inline
size_t
241 __NTH (confstr (int __name
, char *__buf
, size_t __len
))
243 if (__bos (__buf
) != (size_t) -1)
245 if (!__builtin_constant_p (__len
))
246 return __confstr_chk (__name
, __buf
, __len
, __bos (__buf
));
248 if (__bos (__buf
) < __len
)
249 return __confstr_chk_warn (__name
, __buf
, __len
, __bos (__buf
));
251 return __confstr_alias (__name
, __buf
, __len
);
255 extern int __getgroups_chk (int __size
, __gid_t __list
[], size_t __listlen
)
257 extern int __REDIRECT_NTH (__getgroups_alias
, (int __size
, __gid_t __list
[]),
259 extern int __REDIRECT_NTH (__getgroups_chk_warn
,
260 (int __size
, __gid_t __list
[], size_t __listlen
),
262 __wur
__warnattr ("getgroups called with bigger group count than what "
263 "can fit into destination buffer");
265 __extern_always_inline
int
266 __NTH (getgroups (int __size
, __gid_t __list
[]))
268 if (__bos (__list
) != (size_t) -1)
270 if (!__builtin_constant_p (__size
) || __size
< 0)
271 return __getgroups_chk (__size
, __list
, __bos (__list
));
273 if (__size
* sizeof (__gid_t
) > __bos (__list
))
274 return __getgroups_chk_warn (__size
, __list
, __bos (__list
));
276 return __getgroups_alias (__size
, __list
);
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
)
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");
291 __extern_always_inline
int
292 __NTH (ttyname_r (int __fd
, char *__buf
, size_t __buflen
))
294 if (__bos (__buf
) != (size_t) -1)
296 if (!__builtin_constant_p (__buflen
))
297 return __ttyname_r_chk (__fd
, __buf
, __buflen
, __bos (__buf
));
299 if (__buflen
> __bos (__buf
))
300 return __ttyname_r_chk_warn (__fd
, __buf
, __buflen
, __bos (__buf
));
302 return __ttyname_r_alias (__fd
, __buf
, __buflen
);
306 #if defined __USE_REENTRANT || defined __USE_POSIX199506
307 extern int __getlogin_r_chk (char *__buf
, size_t __buflen
, size_t __nreal
)
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
),
314 __nonnull ((1)) __warnattr ("getlogin_r called with bigger buflen than "
315 "size of destination buffer");
317 __extern_always_inline
int
318 getlogin_r (char *__buf
, size_t __buflen
)
320 if (__bos (__buf
) != (size_t) -1)
322 if (!__builtin_constant_p (__buflen
))
323 return __getlogin_r_chk (__buf
, __buflen
, __bos (__buf
));
325 if (__buflen
> __bos (__buf
))
326 return __getlogin_r_chk_warn (__buf
, __buflen
, __bos (__buf
));
328 return __getlogin_r_alias (__buf
, __buflen
);
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
),
341 __nonnull ((1)) __warnattr ("gethostname called with bigger buflen than "
342 "size of destination buffer");
344 __extern_always_inline
int
345 __NTH (gethostname (char *__buf
, size_t __buflen
))
347 if (__bos (__buf
) != (size_t) -1)
349 if (!__builtin_constant_p (__buflen
))
350 return __gethostname_chk (__buf
, __buflen
, __bos (__buf
));
352 if (__buflen
> __bos (__buf
))
353 return __gethostname_chk_warn (__buf
, __buflen
, __bos (__buf
));
355 return __gethostname_alias (__buf
, __buflen
);
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
,
365 getdomainname
) __nonnull ((1)) __wur
;
366 extern int __REDIRECT_NTH (__getdomainname_chk_warn
,
367 (char *__buf
, size_t __buflen
, size_t __nreal
),
369 __nonnull ((1)) __wur
__warnattr ("getdomainname called with bigger "
370 "buflen than size of destination "
373 __extern_always_inline
int
374 __NTH (getdomainname (char *__buf
, size_t __buflen
))
376 if (__bos (__buf
) != (size_t) -1)
378 if (!__builtin_constant_p (__buflen
))
379 return __getdomainname_chk (__buf
, __buflen
, __bos (__buf
));
381 if (__buflen
> __bos (__buf
))
382 return __getdomainname_chk_warn (__buf
, __buflen
, __bos (__buf
));
384 return __getdomainname_alias (__buf
, __buflen
);