]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/bits/unistd.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / posix / bits / unistd.h
CommitLineData
553cc5f9 1/* Checking macros for unistd functions.
2b778ceb 2 Copyright (C) 2005-2021 Free Software Foundation, Inc.
553cc5f9
UD
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
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
553cc5f9
UD
18
19#ifndef _UNISTD_H
20# error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
21#endif
22
23extern ssize_t __read_chk (int __fd, void *__buf, size_t __nbytes,
06febd8c
MS
24 size_t __buflen)
25 __wur __attr_access ((__write_only__, 2, 3));
60bd9f7c 26extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
06febd8c
MS
27 size_t __nbytes), read)
28 __wur __attr_access ((__write_only__, 2, 3));
d6cd6bf4
UD
29extern 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");
60bd9f7c 34
5ac3ea17 35__fortify_function __wur ssize_t
60bd9f7c
UD
36read (int __fd, void *__buf, size_t __nbytes)
37{
f9de8bfe 38 if (__glibc_objsize0 (__buf) != (size_t) -1)
d6cd6bf4
UD
39 {
40 if (!__builtin_constant_p (__nbytes))
f9de8bfe 41 return __read_chk (__fd, __buf, __nbytes, __glibc_objsize0 (__buf));
d6cd6bf4 42
f9de8bfe
SP
43 if (__nbytes > __glibc_objsize0 (__buf))
44 return __read_chk_warn (__fd, __buf, __nbytes,
45 __glibc_objsize0 (__buf));
d6cd6bf4 46 }
60bd9f7c
UD
47 return __read_alias (__fd, __buf, __nbytes);
48}
553cc5f9
UD
49
50#ifdef __USE_UNIX98
51extern ssize_t __pread_chk (int __fd, void *__buf, size_t __nbytes,
06febd8c
MS
52 __off_t __offset, size_t __bufsize)
53 __wur __attr_access ((__write_only__, 2, 3));
553cc5f9 54extern ssize_t __pread64_chk (int __fd, void *__buf, size_t __nbytes,
06febd8c
MS
55 __off64_t __offset, size_t __bufsize)
56 __wur __attr_access ((__write_only__, 2, 3));
60bd9f7c
UD
57extern ssize_t __REDIRECT (__pread_alias,
58 (int __fd, void *__buf, size_t __nbytes,
06febd8c
MS
59 __off_t __offset), pread)
60 __wur __attr_access ((__write_only__, 2, 3));
60bd9f7c
UD
61extern ssize_t __REDIRECT (__pread64_alias,
62 (int __fd, void *__buf, size_t __nbytes,
06febd8c
MS
63 __off64_t __offset), pread64)
64 __wur __attr_access ((__write_only__, 2, 3));
d6cd6bf4
UD
65extern ssize_t __REDIRECT (__pread_chk_warn,
66 (int __fd, void *__buf, size_t __nbytes,
67 __off_t __offset, size_t __bufsize), __pread_chk)
68 __wur __warnattr ("pread called with bigger length than size of "
69 "the destination buffer");
70extern ssize_t __REDIRECT (__pread64_chk_warn,
71 (int __fd, void *__buf, size_t __nbytes,
72 __off64_t __offset, size_t __bufsize),
73 __pread64_chk)
74 __wur __warnattr ("pread64 called with bigger length than size of "
75 "the destination buffer");
88764ae2 76
553cc5f9 77# ifndef __USE_FILE_OFFSET64
5ac3ea17 78__fortify_function __wur ssize_t
60bd9f7c
UD
79pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
80{
f9de8bfe 81 if (__glibc_objsize0 (__buf) != (size_t) -1)
d6cd6bf4
UD
82 {
83 if (!__builtin_constant_p (__nbytes))
f9de8bfe
SP
84 return __pread_chk (__fd, __buf, __nbytes, __offset,
85 __glibc_objsize0 (__buf));
d6cd6bf4 86
f9de8bfe 87 if ( __nbytes > __glibc_objsize0 (__buf))
d6cd6bf4 88 return __pread_chk_warn (__fd, __buf, __nbytes, __offset,
f9de8bfe 89 __glibc_objsize0 (__buf));
d6cd6bf4 90 }
60bd9f7c
UD
91 return __pread_alias (__fd, __buf, __nbytes, __offset);
92}
553cc5f9 93# else
5ac3ea17 94__fortify_function __wur ssize_t
65fb0d21 95pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
60bd9f7c 96{
f9de8bfe 97 if (__glibc_objsize0 (__buf) != (size_t) -1)
d6cd6bf4
UD
98 {
99 if (!__builtin_constant_p (__nbytes))
f9de8bfe
SP
100 return __pread64_chk (__fd, __buf, __nbytes, __offset,
101 __glibc_objsize0 (__buf));
d6cd6bf4 102
f9de8bfe 103 if ( __nbytes > __glibc_objsize0 (__buf))
d6cd6bf4 104 return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
f9de8bfe 105 __glibc_objsize0 (__buf));
d6cd6bf4
UD
106 }
107
60bd9f7c
UD
108 return __pread64_alias (__fd, __buf, __nbytes, __offset);
109}
553cc5f9
UD
110# endif
111
112# ifdef __USE_LARGEFILE64
5ac3ea17 113__fortify_function __wur ssize_t
60bd9f7c
UD
114pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
115{
f9de8bfe 116 if (__glibc_objsize0 (__buf) != (size_t) -1)
d6cd6bf4
UD
117 {
118 if (!__builtin_constant_p (__nbytes))
f9de8bfe
SP
119 return __pread64_chk (__fd, __buf, __nbytes, __offset,
120 __glibc_objsize0 (__buf));
d6cd6bf4 121
f9de8bfe 122 if ( __nbytes > __glibc_objsize0 (__buf))
d6cd6bf4 123 return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
f9de8bfe 124 __glibc_objsize0 (__buf));
d6cd6bf4
UD
125 }
126
60bd9f7c
UD
127 return __pread64_alias (__fd, __buf, __nbytes, __offset);
128}
553cc5f9
UD
129# endif
130#endif
131
acd7f096 132#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
a784e502 133extern ssize_t __readlink_chk (const char *__restrict __path,
6738b3c0
UD
134 char *__restrict __buf, size_t __len,
135 size_t __buflen)
06febd8c 136 __THROW __nonnull ((1, 2)) __wur __attr_access ((__write_only__, 2, 3));
6738b3c0 137extern ssize_t __REDIRECT_NTH (__readlink_alias,
a784e502 138 (const char *__restrict __path,
6738b3c0 139 char *__restrict __buf, size_t __len), readlink)
06febd8c 140 __nonnull ((1, 2)) __wur __attr_access ((__write_only__, 2, 3));
d6cd6bf4 141extern ssize_t __REDIRECT_NTH (__readlink_chk_warn,
a784e502 142 (const char *__restrict __path,
d6cd6bf4
UD
143 char *__restrict __buf, size_t __len,
144 size_t __buflen), __readlink_chk)
145 __nonnull ((1, 2)) __wur __warnattr ("readlink called with bigger length "
146 "than size of destination buffer");
88764ae2 147
5ac3ea17 148__fortify_function __nonnull ((1, 2)) __wur ssize_t
a784e502 149__NTH (readlink (const char *__restrict __path, char *__restrict __buf,
60bd9f7c
UD
150 size_t __len))
151{
f9de8bfe 152 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
153 {
154 if (!__builtin_constant_p (__len))
f9de8bfe 155 return __readlink_chk (__path, __buf, __len, __glibc_objsize (__buf));
d6cd6bf4 156
f9de8bfe
SP
157 if ( __len > __glibc_objsize (__buf))
158 return __readlink_chk_warn (__path, __buf, __len,
159 __glibc_objsize (__buf));
d6cd6bf4 160 }
60bd9f7c
UD
161 return __readlink_alias (__path, __buf, __len);
162}
553cc5f9
UD
163#endif
164
a346370d 165#ifdef __USE_ATFILE
a784e502 166extern ssize_t __readlinkat_chk (int __fd, const char *__restrict __path,
a346370d
UD
167 char *__restrict __buf, size_t __len,
168 size_t __buflen)
06febd8c 169 __THROW __nonnull ((2, 3)) __wur __attr_access ((__write_only__, 3, 4));
a346370d 170extern ssize_t __REDIRECT_NTH (__readlinkat_alias,
a784e502 171 (int __fd, const char *__restrict __path,
a346370d
UD
172 char *__restrict __buf, size_t __len),
173 readlinkat)
06febd8c 174 __nonnull ((2, 3)) __wur __attr_access ((__write_only__, 3, 4));
d6cd6bf4 175extern ssize_t __REDIRECT_NTH (__readlinkat_chk_warn,
a784e502 176 (int __fd, const char *__restrict __path,
d6cd6bf4
UD
177 char *__restrict __buf, size_t __len,
178 size_t __buflen), __readlinkat_chk)
179 __nonnull ((2, 3)) __wur __warnattr ("readlinkat called with bigger "
180 "length than size of destination "
181 "buffer");
a346370d 182
5ac3ea17 183__fortify_function __nonnull ((2, 3)) __wur ssize_t
a784e502 184__NTH (readlinkat (int __fd, const char *__restrict __path,
a346370d
UD
185 char *__restrict __buf, size_t __len))
186{
f9de8bfe 187 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
188 {
189 if (!__builtin_constant_p (__len))
f9de8bfe
SP
190 return __readlinkat_chk (__fd, __path, __buf, __len,
191 __glibc_objsize (__buf));
d6cd6bf4 192
f9de8bfe 193 if (__len > __glibc_objsize (__buf))
d6cd6bf4 194 return __readlinkat_chk_warn (__fd, __path, __buf, __len,
f9de8bfe 195 __glibc_objsize (__buf));
d6cd6bf4 196 }
a346370d
UD
197 return __readlinkat_alias (__fd, __path, __buf, __len);
198}
199#endif
200
553cc5f9 201extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen)
06febd8c 202 __THROW __wur __attr_access ((__write_only__, 1, 2));
60bd9f7c 203extern char *__REDIRECT_NTH (__getcwd_alias,
06febd8c
MS
204 (char *__buf, size_t __size), getcwd)
205 __wur __attr_access ((__write_only__, 1, 2));
d6cd6bf4
UD
206extern char *__REDIRECT_NTH (__getcwd_chk_warn,
207 (char *__buf, size_t __size, size_t __buflen),
208 __getcwd_chk)
209 __wur __warnattr ("getcwd caller with bigger length than size of "
210 "destination buffer");
88764ae2 211
5ac3ea17 212__fortify_function __wur char *
60bd9f7c
UD
213__NTH (getcwd (char *__buf, size_t __size))
214{
f9de8bfe 215 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
216 {
217 if (!__builtin_constant_p (__size))
f9de8bfe 218 return __getcwd_chk (__buf, __size, __glibc_objsize (__buf));
d6cd6bf4 219
f9de8bfe
SP
220 if (__size > __glibc_objsize (__buf))
221 return __getcwd_chk_warn (__buf, __size, __glibc_objsize (__buf));
d6cd6bf4 222 }
60bd9f7c
UD
223 return __getcwd_alias (__buf, __size);
224}
553cc5f9 225
498afc54 226#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
553cc5f9 227extern char *__getwd_chk (char *__buf, size_t buflen)
06febd8c 228 __THROW __nonnull ((1)) __wur __attr_access ((__write_only__, 1, 2));
d6cd6bf4
UD
229extern char *__REDIRECT_NTH (__getwd_warn, (char *__buf), getwd)
230 __nonnull ((1)) __wur __warnattr ("please use getcwd instead, as getwd "
231 "doesn't specify buffer size");
88764ae2 232
5ac3ea17 233__fortify_function __nonnull ((1)) __attribute_deprecated__ __wur char *
60bd9f7c
UD
234__NTH (getwd (char *__buf))
235{
f9de8bfe
SP
236 if (__glibc_objsize (__buf) != (size_t) -1)
237 return __getwd_chk (__buf, __glibc_objsize (__buf));
d6cd6bf4 238 return __getwd_warn (__buf);
60bd9f7c 239}
553cc5f9 240#endif
9f3731cf
UD
241
242extern size_t __confstr_chk (int __name, char *__buf, size_t __len,
06febd8c
MS
243 size_t __buflen) __THROW
244 __attr_access ((__write_only__, 2, 3));
9f3731cf 245extern size_t __REDIRECT_NTH (__confstr_alias, (int __name, char *__buf,
06febd8c
MS
246 size_t __len), confstr)
247 __attr_access ((__write_only__, 2, 3));
d6cd6bf4
UD
248extern size_t __REDIRECT_NTH (__confstr_chk_warn,
249 (int __name, char *__buf, size_t __len,
250 size_t __buflen), __confstr_chk)
251 __warnattr ("confstr called with bigger length than size of destination "
252 "buffer");
9f3731cf 253
5ac3ea17 254__fortify_function size_t
dc4bb1c2 255__NTH (confstr (int __name, char *__buf, size_t __len))
9f3731cf 256{
f9de8bfe 257 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
258 {
259 if (!__builtin_constant_p (__len))
f9de8bfe 260 return __confstr_chk (__name, __buf, __len, __glibc_objsize (__buf));
d6cd6bf4 261
f9de8bfe
SP
262 if (__glibc_objsize (__buf) < __len)
263 return __confstr_chk_warn (__name, __buf, __len,
264 __glibc_objsize (__buf));
d6cd6bf4 265 }
9f3731cf
UD
266 return __confstr_alias (__name, __buf, __len);
267}
268
269
d6cd6bf4 270extern int __getgroups_chk (int __size, __gid_t __list[], size_t __listlen)
06febd8c 271 __THROW __wur __attr_access ((__write_only__, 2, 1));
9f3731cf 272extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]),
06febd8c 273 getgroups) __wur __attr_access ((__write_only__, 2, 1));
d6cd6bf4
UD
274extern int __REDIRECT_NTH (__getgroups_chk_warn,
275 (int __size, __gid_t __list[], size_t __listlen),
276 __getgroups_chk)
277 __wur __warnattr ("getgroups called with bigger group count than what "
278 "can fit into destination buffer");
9f3731cf 279
5ac3ea17 280__fortify_function int
dc4bb1c2 281__NTH (getgroups (int __size, __gid_t __list[]))
9f3731cf 282{
f9de8bfe 283 if (__glibc_objsize (__list) != (size_t) -1)
d6cd6bf4 284 {
4bed549a 285 if (!__builtin_constant_p (__size) || __size < 0)
f9de8bfe 286 return __getgroups_chk (__size, __list, __glibc_objsize (__list));
d6cd6bf4 287
f9de8bfe
SP
288 if (__size * sizeof (__gid_t) > __glibc_objsize (__list))
289 return __getgroups_chk_warn (__size, __list, __glibc_objsize (__list));
d6cd6bf4 290 }
9f3731cf
UD
291 return __getgroups_alias (__size, __list);
292}
293
294
295extern int __ttyname_r_chk (int __fd, char *__buf, size_t __buflen,
06febd8c
MS
296 size_t __nreal) __THROW __nonnull ((2))
297 __attr_access ((__write_only__, 2, 3));
9f3731cf
UD
298extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
299 size_t __buflen), ttyname_r)
300 __nonnull ((2));
d6cd6bf4
UD
301extern int __REDIRECT_NTH (__ttyname_r_chk_warn,
302 (int __fd, char *__buf, size_t __buflen,
303 size_t __nreal), __ttyname_r_chk)
304 __nonnull ((2)) __warnattr ("ttyname_r called with bigger buflen than "
305 "size of destination buffer");
9f3731cf 306
5ac3ea17 307__fortify_function int
dc4bb1c2 308__NTH (ttyname_r (int __fd, char *__buf, size_t __buflen))
9f3731cf 309{
f9de8bfe 310 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
311 {
312 if (!__builtin_constant_p (__buflen))
f9de8bfe
SP
313 return __ttyname_r_chk (__fd, __buf, __buflen,
314 __glibc_objsize (__buf));
d6cd6bf4 315
f9de8bfe
SP
316 if (__buflen > __glibc_objsize (__buf))
317 return __ttyname_r_chk_warn (__fd, __buf, __buflen,
318 __glibc_objsize (__buf));
d6cd6bf4 319 }
9f3731cf
UD
320 return __ttyname_r_alias (__fd, __buf, __buflen);
321}
322
323
c0307377 324#ifdef __USE_POSIX199506
9f3731cf 325extern int __getlogin_r_chk (char *__buf, size_t __buflen, size_t __nreal)
06febd8c 326 __nonnull ((1)) __attr_access ((__write_only__, 1, 2));
9f3731cf
UD
327extern int __REDIRECT (__getlogin_r_alias, (char *__buf, size_t __buflen),
328 getlogin_r) __nonnull ((1));
d6cd6bf4
UD
329extern int __REDIRECT (__getlogin_r_chk_warn,
330 (char *__buf, size_t __buflen, size_t __nreal),
331 __getlogin_r_chk)
332 __nonnull ((1)) __warnattr ("getlogin_r called with bigger buflen than "
333 "size of destination buffer");
9f3731cf 334
5ac3ea17 335__fortify_function int
9f3731cf
UD
336getlogin_r (char *__buf, size_t __buflen)
337{
f9de8bfe 338 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
339 {
340 if (!__builtin_constant_p (__buflen))
f9de8bfe 341 return __getlogin_r_chk (__buf, __buflen, __glibc_objsize (__buf));
d6cd6bf4 342
f9de8bfe
SP
343 if (__buflen > __glibc_objsize (__buf))
344 return __getlogin_r_chk_warn (__buf, __buflen,
345 __glibc_objsize (__buf));
d6cd6bf4 346 }
9f3731cf
UD
347 return __getlogin_r_alias (__buf, __buflen);
348}
349#endif
350
351
498afc54 352#if defined __USE_MISC || defined __USE_UNIX98
9f3731cf 353extern int __gethostname_chk (char *__buf, size_t __buflen, size_t __nreal)
06febd8c 354 __THROW __nonnull ((1)) __attr_access ((__write_only__, 1, 2));
9f3731cf 355extern int __REDIRECT_NTH (__gethostname_alias, (char *__buf, size_t __buflen),
06febd8c
MS
356 gethostname)
357 __nonnull ((1)) __attr_access ((__write_only__, 1, 2));
d6cd6bf4
UD
358extern int __REDIRECT_NTH (__gethostname_chk_warn,
359 (char *__buf, size_t __buflen, size_t __nreal),
360 __gethostname_chk)
361 __nonnull ((1)) __warnattr ("gethostname called with bigger buflen than "
362 "size of destination buffer");
9f3731cf 363
5ac3ea17 364__fortify_function int
dc4bb1c2 365__NTH (gethostname (char *__buf, size_t __buflen))
9f3731cf 366{
f9de8bfe 367 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
368 {
369 if (!__builtin_constant_p (__buflen))
f9de8bfe 370 return __gethostname_chk (__buf, __buflen, __glibc_objsize (__buf));
d6cd6bf4 371
f9de8bfe
SP
372 if (__buflen > __glibc_objsize (__buf))
373 return __gethostname_chk_warn (__buf, __buflen,
374 __glibc_objsize (__buf));
d6cd6bf4 375 }
9f3731cf
UD
376 return __gethostname_alias (__buf, __buflen);
377}
378#endif
379
380
498afc54 381#if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_UNIX98)
9f3731cf 382extern int __getdomainname_chk (char *__buf, size_t __buflen, size_t __nreal)
06febd8c 383 __THROW __nonnull ((1)) __wur __attr_access ((__write_only__, 1, 2));
9f3731cf
UD
384extern int __REDIRECT_NTH (__getdomainname_alias, (char *__buf,
385 size_t __buflen),
06febd8c
MS
386 getdomainname) __nonnull ((1))
387 __wur __attr_access ((__write_only__, 1, 2));
d6cd6bf4
UD
388extern int __REDIRECT_NTH (__getdomainname_chk_warn,
389 (char *__buf, size_t __buflen, size_t __nreal),
390 __getdomainname_chk)
391 __nonnull ((1)) __wur __warnattr ("getdomainname called with bigger "
392 "buflen than size of destination "
393 "buffer");
9f3731cf 394
5ac3ea17 395__fortify_function int
dc4bb1c2 396__NTH (getdomainname (char *__buf, size_t __buflen))
9f3731cf 397{
f9de8bfe 398 if (__glibc_objsize (__buf) != (size_t) -1)
d6cd6bf4
UD
399 {
400 if (!__builtin_constant_p (__buflen))
f9de8bfe 401 return __getdomainname_chk (__buf, __buflen, __glibc_objsize (__buf));
d6cd6bf4 402
f9de8bfe
SP
403 if (__buflen > __glibc_objsize (__buf))
404 return __getdomainname_chk_warn (__buf, __buflen,
405 __glibc_objsize (__buf));
d6cd6bf4 406 }
9f3731cf
UD
407 return __getdomainname_alias (__buf, __buflen);
408}
409#endif