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