glibc (2.38)
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.
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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #ifndef _UNISTD_H
20 # error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
21 #endif
22
23 # include <bits/unistd-decl.h>
24
25 __fortify_function __wur ssize_t
26 read (int __fd, void *__buf, size_t __nbytes)
27 {
28 return __glibc_fortify (read, __nbytes, sizeof (char),
29 __glibc_objsize0 (__buf),
30 __fd, __buf, __nbytes);
31 }
32
33 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
34 # ifndef __USE_FILE_OFFSET64
35 __fortify_function __wur ssize_t
36 pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
37 {
38 return __glibc_fortify (pread, __nbytes, sizeof (char),
39 __glibc_objsize0 (__buf),
40 __fd, __buf, __nbytes, __offset);
41 }
42 # else
43 __fortify_function __wur ssize_t
44 pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
45 {
46 return __glibc_fortify (pread64, __nbytes, sizeof (char),
47 __glibc_objsize0 (__buf),
48 __fd, __buf, __nbytes, __offset);
49 }
50 # endif
51
52 # ifdef __USE_LARGEFILE64
53 __fortify_function __wur ssize_t
54 pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
55 {
56 return __glibc_fortify (pread64, __nbytes, sizeof (char),
57 __glibc_objsize0 (__buf),
58 __fd, __buf, __nbytes, __offset);
59 }
60 # endif
61 #endif
62
63 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
64 __fortify_function __nonnull ((1, 2)) __wur ssize_t
65 __NTH (readlink (const char *__restrict __path, char *__restrict __buf,
66 size_t __len))
67 {
68 return __glibc_fortify (readlink, __len, sizeof (char),
69 __glibc_objsize (__buf),
70 __path, __buf, __len);
71 }
72 #endif
73
74 #ifdef __USE_ATFILE
75 __fortify_function __nonnull ((2, 3)) __wur ssize_t
76 __NTH (readlinkat (int __fd, const char *__restrict __path,
77 char *__restrict __buf, size_t __len))
78 {
79 return __glibc_fortify (readlinkat, __len, sizeof (char),
80 __glibc_objsize (__buf),
81 __fd, __path, __buf, __len);
82 }
83 #endif
84
85 __fortify_function __wur char *
86 __NTH (getcwd (char *__buf, size_t __size))
87 {
88 return __glibc_fortify (getcwd, __size, sizeof (char),
89 __glibc_objsize (__buf),
90 __buf, __size);
91 }
92
93 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
94 __fortify_function __nonnull ((1)) __attribute_deprecated__ __wur char *
95 __NTH (getwd (char *__buf))
96 {
97 if (__glibc_objsize (__buf) != (size_t) -1)
98 return __getwd_chk (__buf, __glibc_objsize (__buf));
99 return __getwd_warn (__buf);
100 }
101 #endif
102
103 __fortify_function size_t
104 __NTH (confstr (int __name, char *__buf, size_t __len))
105 {
106 return __glibc_fortify (confstr, __len, sizeof (char),
107 __glibc_objsize (__buf),
108 __name, __buf, __len);
109 }
110
111
112 __fortify_function int
113 __NTH (getgroups (int __size, __gid_t __list[]))
114 {
115 return __glibc_fortify (getgroups, __size, sizeof (__gid_t),
116 __glibc_objsize (__list),
117 __size, __list);
118 }
119
120
121 __fortify_function int
122 __NTH (ttyname_r (int __fd, char *__buf, size_t __buflen))
123 {
124 return __glibc_fortify (ttyname_r, __buflen, sizeof (char),
125 __glibc_objsize (__buf),
126 __fd, __buf, __buflen);
127 }
128
129
130 #ifdef __USE_POSIX199506
131 __fortify_function int
132 getlogin_r (char *__buf, size_t __buflen)
133 {
134 return __glibc_fortify (getlogin_r, __buflen, sizeof (char),
135 __glibc_objsize (__buf),
136 __buf, __buflen);
137 }
138 #endif
139
140
141 #if defined __USE_MISC || defined __USE_UNIX98
142 __fortify_function int
143 __NTH (gethostname (char *__buf, size_t __buflen))
144 {
145 return __glibc_fortify (gethostname, __buflen, sizeof (char),
146 __glibc_objsize (__buf),
147 __buf, __buflen);
148 }
149 #endif
150
151
152 #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_UNIX98)
153 __fortify_function int
154 __NTH (getdomainname (char *__buf, size_t __buflen))
155 {
156 return __glibc_fortify (getdomainname, __buflen, sizeof (char),
157 __glibc_objsize (__buf),
158 __buf, __buflen);
159 }
160 #endif