1 /* Checking macros for unistd functions.
2 Copyright (C) 2005, 2006 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
;
29 extern __always_inline __wur ssize_t
30 read (int __fd
, void *__buf
, size_t __nbytes
)
32 if (__bos0 (__buf
) != (size_t) -1
33 && (!__builtin_constant_p (__nbytes
) || __nbytes
> __bos0 (__buf
)))
34 return __read_chk (__fd
, __buf
, __nbytes
, __bos0 (__buf
));
35 return __read_alias (__fd
, __buf
, __nbytes
);
39 extern ssize_t
__pread_chk (int __fd
, void *__buf
, size_t __nbytes
,
40 __off_t __offset
, size_t __bufsize
) __wur
;
41 extern ssize_t
__pread64_chk (int __fd
, void *__buf
, size_t __nbytes
,
42 __off64_t __offset
, size_t __bufsize
) __wur
;
43 extern ssize_t
__REDIRECT (__pread_alias
,
44 (int __fd
, void *__buf
, size_t __nbytes
,
45 __off_t __offset
), pread
) __wur
;
46 extern ssize_t
__REDIRECT (__pread64_alias
,
47 (int __fd
, void *__buf
, size_t __nbytes
,
48 __off64_t __offset
), pread64
) __wur
;
50 # ifndef __USE_FILE_OFFSET64
51 extern __always_inline __wur ssize_t
52 pread (int __fd
, void *__buf
, size_t __nbytes
, __off_t __offset
)
54 if (__bos0 (__buf
) != (size_t) -1
55 && (!__builtin_constant_p (__nbytes
) || __nbytes
> __bos0 (__buf
)))
56 return __pread_chk (__fd
, __buf
, __nbytes
, __offset
, __bos0 (__buf
));
57 return __pread_alias (__fd
, __buf
, __nbytes
, __offset
);
60 extern __always_inline __wur ssize_t
61 pread (int __fd
, void *__buf
, size_t __nbytes
, __off64_t __offset
)
63 if (__bos0 (__buf
) != (size_t) -1
64 && (!__builtin_constant_p (__nbytes
) || __nbytes
> __bos0 (__buf
)))
65 return __pread64_chk (__fd
, __buf
, __nbytes
, __offset
, __bos0 (__buf
));
66 return __pread64_alias (__fd
, __buf
, __nbytes
, __offset
);
70 # ifdef __USE_LARGEFILE64
71 extern __always_inline __wur ssize_t
72 pread64 (int __fd
, void *__buf
, size_t __nbytes
, __off64_t __offset
)
74 if (__bos0 (__buf
) != (size_t) -1
75 && (!__builtin_constant_p (__nbytes
) || __nbytes
> __bos0 (__buf
)))
76 return __pread64_chk (__fd
, __buf
, __nbytes
, __offset
, __bos0 (__buf
));
77 return __pread64_alias (__fd
, __buf
, __nbytes
, __offset
);
82 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
83 extern ssize_t
__readlink_chk (__const
char *__restrict __path
,
84 char *__restrict __buf
, size_t __len
,
86 __THROW
__nonnull ((1, 2)) __wur
;
87 extern ssize_t
__REDIRECT_NTH (__readlink_alias
,
88 (__const
char *__restrict __path
,
89 char *__restrict __buf
, size_t __len
), readlink
)
90 __nonnull ((1, 2)) __wur
;
92 extern __always_inline
__nonnull ((1, 2)) __wur ssize_t
93 __NTH (readlink (__const
char *__restrict __path
, char *__restrict __buf
,
96 if (__bos (__buf
) != (size_t) -1
97 && (!__builtin_constant_p (__len
) || __len
> __bos (__buf
)))
98 return __readlink_chk (__path
, __buf
, __len
, __bos (__buf
));
99 return __readlink_alias (__path
, __buf
, __len
);
104 extern ssize_t
__readlinkat_chk (int __fd
, __const
char *__restrict __path
,
105 char *__restrict __buf
, size_t __len
,
107 __THROW
__nonnull ((2, 3)) __wur
;
108 extern ssize_t
__REDIRECT_NTH (__readlinkat_alias
,
109 (int __fd
, __const
char *__restrict __path
,
110 char *__restrict __buf
, size_t __len
),
112 __nonnull ((2, 3)) __wur
;
114 extern __always_inline
__nonnull ((2, 3)) __wur ssize_t
115 __NTH (readlinkat (int __fd
, __const
char *__restrict __path
,
116 char *__restrict __buf
, size_t __len
))
118 if (__bos (__buf
) != (size_t) -1
119 && (!__builtin_constant_p (__len
) || __len
> __bos (__buf
)))
120 return __readlinkat_chk (__fd
, __path
, __buf
, __len
, __bos (__buf
));
121 return __readlinkat_alias (__fd
, __path
, __buf
, __len
);
125 extern char *__getcwd_chk (char *__buf
, size_t __size
, size_t __buflen
)
127 extern char *__REDIRECT_NTH (__getcwd_alias
,
128 (char *__buf
, size_t __size
), getcwd
) __wur
;
130 extern __always_inline __wur
char *
131 __NTH (getcwd (char *__buf
, size_t __size
))
133 if (__bos (__buf
) != (size_t) -1
134 && (!__builtin_constant_p (__size
) || __size
> __bos (__buf
)))
135 return __getcwd_chk (__buf
, __size
, __bos (__buf
));
136 return __getcwd_alias (__buf
, __size
);
139 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
140 extern char *__getwd_chk (char *__buf
, size_t buflen
)
141 __THROW
__nonnull ((1)) __wur
;
142 extern char *__REDIRECT_NTH (__getwd_alias
, (char *__buf
), getwd
)
143 __nonnull ((1)) __wur
;
145 extern __always_inline
__nonnull ((1)) __attribute_deprecated__ __wur
char *
146 __NTH (getwd (char *__buf
))
148 if (__bos (__buf
) != (size_t) -1)
149 return __getwd_chk (__buf
, __bos (__buf
));
150 return __getwd_alias (__buf
);
154 extern size_t __confstr_chk (int __name
, char *__buf
, size_t __len
,
155 size_t __buflen
) __THROW
;
156 extern size_t __REDIRECT_NTH (__confstr_alias
, (int __name
, char *__buf
,
157 size_t __len
), confstr
);
159 extern __always_inline
size_t
160 __NTH (confstr (int __name
, char *__buf
, size_t __len
))
162 if (__bos (__buf
) != (size_t) -1
163 && (!__builtin_constant_p (__len
) || __bos (__buf
) < __len
))
164 return __confstr_chk (__name
, __buf
, __len
, __bos (__buf
));
165 return __confstr_alias (__name
, __buf
, __len
);
169 extern int __getgroups_chk (int __size
, __gid_t __list
[], size_t listlen
)
171 extern int __REDIRECT_NTH (__getgroups_alias
, (int __size
, __gid_t __list
[]),
174 extern __always_inline
int
175 __NTH (getgroups (int __size
, __gid_t __list
[]))
177 if (__bos (__list
) != (size_t) -1
178 && (!__builtin_constant_p (__size
)
179 || __size
* sizeof (__gid_t
) > __bos (__list
)))
180 return __getgroups_chk (__size
, __list
, __bos (__list
));
181 return __getgroups_alias (__size
, __list
);
185 extern int __ttyname_r_chk (int __fd
, char *__buf
, size_t __buflen
,
186 size_t __nreal
) __THROW
__nonnull ((2));
187 extern int __REDIRECT_NTH (__ttyname_r_alias
, (int __fd
, char *__buf
,
188 size_t __buflen
), ttyname_r
)
191 extern __always_inline
int
192 __NTH (ttyname_r (int __fd
, char *__buf
, size_t __buflen
))
194 if (__bos (__buf
) != (size_t) -1
195 && (!__builtin_constant_p (__buflen
) || __buflen
> __bos (__buf
)))
196 return __ttyname_r_chk (__fd
, __buf
, __buflen
, __bos (__buf
));
197 return __ttyname_r_alias (__fd
, __buf
, __buflen
);
201 #if defined __USE_REENTRANT || defined __USE_UNIX98
202 extern int __getlogin_r_chk (char *__buf
, size_t __buflen
, size_t __nreal
)
204 extern int __REDIRECT (__getlogin_r_alias
, (char *__buf
, size_t __buflen
),
205 getlogin_r
) __nonnull ((1));
207 extern __always_inline
int
208 getlogin_r (char *__buf
, size_t __buflen
)
210 if (__bos (__buf
) != (size_t) -1
211 && (!__builtin_constant_p (__buflen
) || __buflen
> __bos (__buf
)))
212 return __getlogin_r_chk (__buf
, __buflen
, __bos (__buf
));
213 return __getlogin_r_alias (__buf
, __buflen
);
218 #if defined __USE_BSD || defined __USE_UNIX98
219 extern int __gethostname_chk (char *__buf
, size_t __buflen
, size_t __nreal
)
220 __THROW
__nonnull ((1));
221 extern int __REDIRECT_NTH (__gethostname_alias
, (char *__buf
, size_t __buflen
),
222 gethostname
) __nonnull ((1));
224 extern __always_inline
int
225 __NTH (gethostname (char *__buf
, size_t __buflen
))
227 if (__bos (__buf
) != (size_t) -1
228 && (!__builtin_constant_p (__buflen
) || __buflen
> __bos (__buf
)))
229 return __gethostname_chk (__buf
, __buflen
, __bos (__buf
));
230 return __gethostname_alias (__buf
, __buflen
);
235 #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
236 extern int __getdomainname_chk (char *__buf
, size_t __buflen
, size_t __nreal
)
237 __THROW
__nonnull ((1)) __wur
;
238 extern int __REDIRECT_NTH (__getdomainname_alias
, (char *__buf
,
240 getdomainname
) __nonnull ((1)) __wur
;
242 extern __always_inline
int
243 __NTH (getdomainname (char *__buf
, size_t __buflen
))
245 if (__bos (__buf
) != (size_t) -1
246 && (!__builtin_constant_p (__buflen
) || __buflen
> __bos (__buf
)))
247 return __getdomainname_chk (__buf
, __buflen
, __bos (__buf
));
248 return __getdomainname_alias (__buf
, __buflen
);