1 /* Checking macros for unistd functions.
2 Copyright (C) 2005-2024 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 # include <bits/unistd-decl.h>
25 __fortify_function __attribute_overloadable__ __wur ssize_t
26 read (int __fd
, __fortify_clang_overload_arg0 (void *, ,__buf
), size_t __nbytes
)
27 __fortify_clang_warning_only_if_bos0_lt (__nbytes
, __buf
,
28 "read called with bigger length than "
29 "size of the destination buffer")
32 return __glibc_fortify (read
, __nbytes
, sizeof (char),
33 __glibc_objsize0 (__buf
),
34 __fd
, __buf
, __nbytes
);
37 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
38 # ifndef __USE_FILE_OFFSET64
39 __fortify_function __attribute_overloadable__ __wur ssize_t
40 pread (int __fd
, __fortify_clang_overload_arg0 (void *, ,__buf
),
41 size_t __nbytes
, __off_t __offset
)
42 __fortify_clang_warning_only_if_bos0_lt (__nbytes
, __buf
,
43 "pread called with bigger length than "
44 "size of the destination buffer")
46 return __glibc_fortify (pread
, __nbytes
, sizeof (char),
47 __glibc_objsize0 (__buf
),
48 __fd
, __buf
, __nbytes
, __offset
);
51 __fortify_function __attribute_overloadable__ __wur ssize_t
52 pread (int __fd
, __fortify_clang_overload_arg0 (void *, ,__buf
),
53 size_t __nbytes
, __off64_t __offset
)
54 __fortify_clang_warning_only_if_bos0_lt (__nbytes
, __buf
,
55 "pread called with bigger length than "
56 "size of the destination buffer")
58 return __glibc_fortify (pread64
, __nbytes
, sizeof (char),
59 __glibc_objsize0 (__buf
),
60 __fd
, __buf
, __nbytes
, __offset
);
64 # ifdef __USE_LARGEFILE64
65 __fortify_function __attribute_overloadable__ __wur ssize_t
66 pread64 (int __fd
, __fortify_clang_overload_arg0 (void *, ,__buf
),
67 size_t __nbytes
, __off64_t __offset
)
68 __fortify_clang_warning_only_if_bos0_lt (__nbytes
, __buf
,
69 "pread64 called with bigger length than "
70 "size of the destination buffer")
72 return __glibc_fortify (pread64
, __nbytes
, sizeof (char),
73 __glibc_objsize0 (__buf
),
74 __fd
, __buf
, __nbytes
, __offset
);
79 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
80 __fortify_function __attribute_overloadable__
__nonnull ((1, 2)) __wur ssize_t
81 __NTH (readlink (const char *__restrict __path
,
82 __fortify_clang_overload_arg0 (char *, __restrict
, __buf
),
84 __fortify_clang_warning_only_if_bos_lt (__len
, __buf
,
85 "readlink called with bigger length "
86 "than size of destination buffer")
89 return __glibc_fortify (readlink
, __len
, sizeof (char),
90 __glibc_objsize (__buf
),
91 __path
, __buf
, __len
);
96 __fortify_function __attribute_overloadable__
__nonnull ((2, 3)) __wur ssize_t
97 __NTH (readlinkat (int __fd
, const char *__restrict __path
,
98 __fortify_clang_overload_arg0 (char *, __restrict
, __buf
),
100 __fortify_clang_warning_only_if_bos_lt (__len
, __buf
,
101 "readlinkat called with bigger length "
102 "than size of destination buffer")
104 return __glibc_fortify (readlinkat
, __len
, sizeof (char),
105 __glibc_objsize (__buf
),
106 __fd
, __path
, __buf
, __len
);
110 __fortify_function __attribute_overloadable__ __wur
char *
111 __NTH (getcwd (__fortify_clang_overload_arg (char *, , __buf
), size_t __size
))
112 __fortify_clang_warning_only_if_bos_lt (__size
, __buf
,
113 "getcwd called with bigger length "
114 "than size of destination buffer")
116 return __glibc_fortify (getcwd
, __size
, sizeof (char),
117 __glibc_objsize (__buf
),
121 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
122 __fortify_function __attribute_overloadable__
__nonnull ((1))
123 __attribute_deprecated__ __wur
char *
124 __NTH (getwd (__fortify_clang_overload_arg (char *,, __buf
)))
126 if (__glibc_objsize (__buf
) != (size_t) -1)
127 return __getwd_chk (__buf
, __glibc_objsize (__buf
));
128 return __getwd_warn (__buf
);
132 __fortify_function __attribute_overloadable__
size_t
133 __NTH (confstr (int __name
, __fortify_clang_overload_arg (char *, ,__buf
),
135 __fortify_clang_warning_only_if_bos_lt (__len
, __buf
,
136 "confstr called with bigger length than "
137 "size of destination buffer")
139 return __glibc_fortify (confstr
, __len
, sizeof (char),
140 __glibc_objsize (__buf
),
141 __name
, __buf
, __len
);
145 __fortify_function __attribute_overloadable__
int
146 __NTH (getgroups (int __size
,
147 __fortify_clang_overload_arg (__gid_t
*, , __list
)))
148 __fortify_clang_warning_only_if_bos_lt (__size
* sizeof (__gid_t
), __list
,
149 "getgroups called with bigger group "
150 "count than what can fit into "
151 "destination buffer")
153 return __glibc_fortify (getgroups
, __size
, sizeof (__gid_t
),
154 __glibc_objsize (__list
),
159 __fortify_function __attribute_overloadable__
int
160 __NTH (ttyname_r (int __fd
,
161 __fortify_clang_overload_arg (char *, ,__buf
),
163 __fortify_clang_warning_only_if_bos_lt (__buflen
, __buf
,
164 "ttyname_r called with bigger buflen "
165 "than size of destination buffer")
167 return __glibc_fortify (ttyname_r
, __buflen
, sizeof (char),
168 __glibc_objsize (__buf
),
169 __fd
, __buf
, __buflen
);
173 #ifdef __USE_POSIX199506
174 __fortify_function __attribute_overloadable__
int
175 getlogin_r (__fortify_clang_overload_arg (char *, ,__buf
), size_t __buflen
)
176 __fortify_clang_warning_only_if_bos_lt (__buflen
, __buf
,
177 "getlogin_r called with bigger buflen "
178 "than size of destination buffer")
180 return __glibc_fortify (getlogin_r
, __buflen
, sizeof (char),
181 __glibc_objsize (__buf
),
187 #if defined __USE_MISC || defined __USE_UNIX98
188 __fortify_function __attribute_overloadable__
int
189 __NTH (gethostname (__fortify_clang_overload_arg (char *, ,__buf
),
191 __fortify_clang_warning_only_if_bos_lt (__buflen
, __buf
,
192 "gethostname called with bigger buflen "
193 "than size of destination buffer")
195 return __glibc_fortify (gethostname
, __buflen
, sizeof (char),
196 __glibc_objsize (__buf
),
202 #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_UNIX98)
203 __fortify_function __attribute_overloadable__
int
204 __NTH (getdomainname (__fortify_clang_overload_arg (char *, ,__buf
),
206 __fortify_clang_warning_only_if_bos_lt (__buflen
, __buf
,
207 "getdomainname called with bigger "
208 "buflen than size of destination buffer")
210 return __glibc_fortify (getdomainname
, __buflen
, sizeof (char),
211 __glibc_objsize (__buf
),