1 /* Checking macros for unistd functions.
2 Copyright (C) 2005-2023 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, see
17 <https://www.gnu.org/licenses/>. */
20 # error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
23 extern ssize_t
__read_chk (int __fd
, void *__buf
, size_t __nbytes
,
25 __wur
__attr_access ((__write_only__
, 2, 3));
26 extern ssize_t
__REDIRECT (__read_alias
, (int __fd
, void *__buf
,
27 size_t __nbytes
), read
)
28 __wur
__attr_access ((__write_only__
, 2, 3));
29 extern ssize_t
__REDIRECT (__read_chk_warn
,
30 (int __fd
, void *__buf
, size_t __nbytes
,
31 size_t __buflen
), __read_chk
)
32 __wur
__warnattr ("read called with bigger length than size of "
33 "the destination buffer");
35 __fortify_function __wur ssize_t
36 read (int __fd
, void *__buf
, size_t __nbytes
)
38 return __glibc_fortify (read
, __nbytes
, sizeof (char),
39 __glibc_objsize0 (__buf
),
40 __fd
, __buf
, __nbytes
);
43 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
44 extern ssize_t
__pread_chk (int __fd
, void *__buf
, size_t __nbytes
,
45 __off_t __offset
, size_t __bufsize
)
46 __wur
__attr_access ((__write_only__
, 2, 3));
47 extern ssize_t
__pread64_chk (int __fd
, void *__buf
, size_t __nbytes
,
48 __off64_t __offset
, size_t __bufsize
)
49 __wur
__attr_access ((__write_only__
, 2, 3));
50 extern ssize_t
__REDIRECT (__pread_alias
,
51 (int __fd
, void *__buf
, size_t __nbytes
,
52 __off_t __offset
), pread
)
53 __wur
__attr_access ((__write_only__
, 2, 3));
54 extern ssize_t
__REDIRECT (__pread64_alias
,
55 (int __fd
, void *__buf
, size_t __nbytes
,
56 __off64_t __offset
), pread64
)
57 __wur
__attr_access ((__write_only__
, 2, 3));
58 extern ssize_t
__REDIRECT (__pread_chk_warn
,
59 (int __fd
, void *__buf
, size_t __nbytes
,
60 __off_t __offset
, size_t __bufsize
), __pread_chk
)
61 __wur
__warnattr ("pread called with bigger length than size of "
62 "the destination buffer");
63 extern ssize_t
__REDIRECT (__pread64_chk_warn
,
64 (int __fd
, void *__buf
, size_t __nbytes
,
65 __off64_t __offset
, size_t __bufsize
),
67 __wur
__warnattr ("pread64 called with bigger length than size of "
68 "the destination buffer");
70 # ifndef __USE_FILE_OFFSET64
71 __fortify_function __wur ssize_t
72 pread (int __fd
, void *__buf
, size_t __nbytes
, __off_t __offset
)
74 return __glibc_fortify (pread
, __nbytes
, sizeof (char),
75 __glibc_objsize0 (__buf
),
76 __fd
, __buf
, __nbytes
, __offset
);
79 __fortify_function __wur ssize_t
80 pread (int __fd
, void *__buf
, size_t __nbytes
, __off64_t __offset
)
82 return __glibc_fortify (pread64
, __nbytes
, sizeof (char),
83 __glibc_objsize0 (__buf
),
84 __fd
, __buf
, __nbytes
, __offset
);
88 # ifdef __USE_LARGEFILE64
89 __fortify_function __wur ssize_t
90 pread64 (int __fd
, void *__buf
, size_t __nbytes
, __off64_t __offset
)
92 return __glibc_fortify (pread64
, __nbytes
, sizeof (char),
93 __glibc_objsize0 (__buf
),
94 __fd
, __buf
, __nbytes
, __offset
);
99 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
100 extern ssize_t
__readlink_chk (const char *__restrict __path
,
101 char *__restrict __buf
, size_t __len
,
103 __THROW
__nonnull ((1, 2)) __wur
__attr_access ((__write_only__
, 2, 3));
104 extern ssize_t
__REDIRECT_NTH (__readlink_alias
,
105 (const char *__restrict __path
,
106 char *__restrict __buf
, size_t __len
), readlink
)
107 __nonnull ((1, 2)) __wur
__attr_access ((__write_only__
, 2, 3));
108 extern ssize_t
__REDIRECT_NTH (__readlink_chk_warn
,
109 (const char *__restrict __path
,
110 char *__restrict __buf
, size_t __len
,
111 size_t __buflen
), __readlink_chk
)
112 __nonnull ((1, 2)) __wur
__warnattr ("readlink called with bigger length "
113 "than size of destination buffer");
115 __fortify_function
__nonnull ((1, 2)) __wur ssize_t
116 __NTH (readlink (const char *__restrict __path
, char *__restrict __buf
,
119 return __glibc_fortify (readlink
, __len
, sizeof (char),
120 __glibc_objsize (__buf
),
121 __path
, __buf
, __len
);
126 extern ssize_t
__readlinkat_chk (int __fd
, const char *__restrict __path
,
127 char *__restrict __buf
, size_t __len
,
129 __THROW
__nonnull ((2, 3)) __wur
__attr_access ((__write_only__
, 3, 4));
130 extern ssize_t
__REDIRECT_NTH (__readlinkat_alias
,
131 (int __fd
, const char *__restrict __path
,
132 char *__restrict __buf
, size_t __len
),
134 __nonnull ((2, 3)) __wur
__attr_access ((__write_only__
, 3, 4));
135 extern ssize_t
__REDIRECT_NTH (__readlinkat_chk_warn
,
136 (int __fd
, const char *__restrict __path
,
137 char *__restrict __buf
, size_t __len
,
138 size_t __buflen
), __readlinkat_chk
)
139 __nonnull ((2, 3)) __wur
__warnattr ("readlinkat called with bigger "
140 "length than size of destination "
143 __fortify_function
__nonnull ((2, 3)) __wur ssize_t
144 __NTH (readlinkat (int __fd
, const char *__restrict __path
,
145 char *__restrict __buf
, size_t __len
))
147 return __glibc_fortify (readlinkat
, __len
, sizeof (char),
148 __glibc_objsize (__buf
),
149 __fd
, __path
, __buf
, __len
);
153 extern char *__getcwd_chk (char *__buf
, size_t __size
, size_t __buflen
)
155 extern char *__REDIRECT_NTH (__getcwd_alias
,
156 (char *__buf
, size_t __size
), getcwd
) __wur
;
157 extern char *__REDIRECT_NTH (__getcwd_chk_warn
,
158 (char *__buf
, size_t __size
, size_t __buflen
),
160 __wur
__warnattr ("getcwd caller with bigger length than size of "
161 "destination buffer");
163 __fortify_function __wur
char *
164 __NTH (getcwd (char *__buf
, size_t __size
))
166 return __glibc_fortify (getcwd
, __size
, sizeof (char),
167 __glibc_objsize (__buf
),
171 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
172 extern char *__getwd_chk (char *__buf
, size_t buflen
)
173 __THROW
__nonnull ((1)) __wur
__attr_access ((__write_only__
, 1, 2));
174 extern char *__REDIRECT_NTH (__getwd_warn
, (char *__buf
), getwd
)
175 __nonnull ((1)) __wur
__warnattr ("please use getcwd instead, as getwd "
176 "doesn't specify buffer size");
178 __fortify_function
__nonnull ((1)) __attribute_deprecated__ __wur
char *
179 __NTH (getwd (char *__buf
))
181 if (__glibc_objsize (__buf
) != (size_t) -1)
182 return __getwd_chk (__buf
, __glibc_objsize (__buf
));
183 return __getwd_warn (__buf
);
187 extern size_t __confstr_chk (int __name
, char *__buf
, size_t __len
,
188 size_t __buflen
) __THROW
189 __attr_access ((__write_only__
, 2, 3));
190 extern size_t __REDIRECT_NTH (__confstr_alias
, (int __name
, char *__buf
,
191 size_t __len
), confstr
)
192 __attr_access ((__write_only__
, 2, 3));
193 extern size_t __REDIRECT_NTH (__confstr_chk_warn
,
194 (int __name
, char *__buf
, size_t __len
,
195 size_t __buflen
), __confstr_chk
)
196 __warnattr ("confstr called with bigger length than size of destination "
199 __fortify_function
size_t
200 __NTH (confstr (int __name
, char *__buf
, size_t __len
))
202 return __glibc_fortify (confstr
, __len
, sizeof (char),
203 __glibc_objsize (__buf
),
204 __name
, __buf
, __len
);
208 extern int __getgroups_chk (int __size
, __gid_t __list
[], size_t __listlen
)
209 __THROW __wur
__attr_access ((__write_only__
, 2, 1));
210 extern int __REDIRECT_NTH (__getgroups_alias
, (int __size
, __gid_t __list
[]),
211 getgroups
) __wur
__attr_access ((__write_only__
, 2, 1));
212 extern int __REDIRECT_NTH (__getgroups_chk_warn
,
213 (int __size
, __gid_t __list
[], size_t __listlen
),
215 __wur
__warnattr ("getgroups called with bigger group count than what "
216 "can fit into destination buffer");
218 __fortify_function
int
219 __NTH (getgroups (int __size
, __gid_t __list
[]))
221 return __glibc_fortify (getgroups
, __size
, sizeof (__gid_t
),
222 __glibc_objsize (__list
),
227 extern int __ttyname_r_chk (int __fd
, char *__buf
, size_t __buflen
,
228 size_t __nreal
) __THROW
__nonnull ((2))
229 __attr_access ((__write_only__
, 2, 3));
230 extern int __REDIRECT_NTH (__ttyname_r_alias
, (int __fd
, char *__buf
,
231 size_t __buflen
), ttyname_r
)
233 extern int __REDIRECT_NTH (__ttyname_r_chk_warn
,
234 (int __fd
, char *__buf
, size_t __buflen
,
235 size_t __nreal
), __ttyname_r_chk
)
236 __nonnull ((2)) __warnattr ("ttyname_r called with bigger buflen than "
237 "size of destination buffer");
239 __fortify_function
int
240 __NTH (ttyname_r (int __fd
, char *__buf
, size_t __buflen
))
242 return __glibc_fortify (ttyname_r
, __buflen
, sizeof (char),
243 __glibc_objsize (__buf
),
244 __fd
, __buf
, __buflen
);
248 #ifdef __USE_POSIX199506
249 extern int __getlogin_r_chk (char *__buf
, size_t __buflen
, size_t __nreal
)
250 __nonnull ((1)) __attr_access ((__write_only__
, 1, 2));
251 extern int __REDIRECT (__getlogin_r_alias
, (char *__buf
, size_t __buflen
),
252 getlogin_r
) __nonnull ((1));
253 extern int __REDIRECT (__getlogin_r_chk_warn
,
254 (char *__buf
, size_t __buflen
, size_t __nreal
),
256 __nonnull ((1)) __warnattr ("getlogin_r called with bigger buflen than "
257 "size of destination buffer");
259 __fortify_function
int
260 getlogin_r (char *__buf
, size_t __buflen
)
262 return __glibc_fortify (getlogin_r
, __buflen
, sizeof (char),
263 __glibc_objsize (__buf
),
269 #if defined __USE_MISC || defined __USE_UNIX98
270 extern int __gethostname_chk (char *__buf
, size_t __buflen
, size_t __nreal
)
271 __THROW
__nonnull ((1)) __attr_access ((__write_only__
, 1, 2));
272 extern int __REDIRECT_NTH (__gethostname_alias
, (char *__buf
, size_t __buflen
),
274 __nonnull ((1)) __attr_access ((__write_only__
, 1, 2));
275 extern int __REDIRECT_NTH (__gethostname_chk_warn
,
276 (char *__buf
, size_t __buflen
, size_t __nreal
),
278 __nonnull ((1)) __warnattr ("gethostname called with bigger buflen than "
279 "size of destination buffer");
281 __fortify_function
int
282 __NTH (gethostname (char *__buf
, size_t __buflen
))
284 return __glibc_fortify (gethostname
, __buflen
, sizeof (char),
285 __glibc_objsize (__buf
),
291 #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_UNIX98)
292 extern int __getdomainname_chk (char *__buf
, size_t __buflen
, size_t __nreal
)
293 __THROW
__nonnull ((1)) __wur
__attr_access ((__write_only__
, 1, 2));
294 extern int __REDIRECT_NTH (__getdomainname_alias
, (char *__buf
,
296 getdomainname
) __nonnull ((1))
297 __wur
__attr_access ((__write_only__
, 1, 2));
298 extern int __REDIRECT_NTH (__getdomainname_chk_warn
,
299 (char *__buf
, size_t __buflen
, size_t __nreal
),
301 __nonnull ((1)) __wur
__warnattr ("getdomainname called with bigger "
302 "buflen than size of destination "
305 __fortify_function
int
306 __NTH (getdomainname (char *__buf
, size_t __buflen
))
308 return __glibc_fortify (getdomainname
, __buflen
, sizeof (char),
309 __glibc_objsize (__buf
),