| 1 | /* Checking macros for unistd functions. |
| 2 | Copyright (C) 2005-2026 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 __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") |
| 30 | |
| 31 | { |
| 32 | return __glibc_fortify (read, __nbytes, sizeof (char), |
| 33 | 			 __glibc_objsize0 (__buf), |
| 34 | 			 __fd, __buf, __nbytes); |
| 35 | } |
| 36 | |
| 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") |
| 45 | { |
| 46 | return __glibc_fortify (pread, __nbytes, sizeof (char), |
| 47 | 			 __glibc_objsize0 (__buf), |
| 48 | 			 __fd, __buf, __nbytes, __offset); |
| 49 | } |
| 50 | # else |
| 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") |
| 57 | { |
| 58 | return __glibc_fortify (pread64, __nbytes, sizeof (char), |
| 59 | 			 __glibc_objsize0 (__buf), |
| 60 | 			 __fd, __buf, __nbytes, __offset); |
| 61 | } |
| 62 | # endif |
| 63 | |
| 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") |
| 71 | { |
| 72 | return __glibc_fortify (pread64, __nbytes, sizeof (char), |
| 73 | 			 __glibc_objsize0 (__buf), |
| 74 | 			 __fd, __buf, __nbytes, __offset); |
| 75 | } |
| 76 | # endif |
| 77 | #endif |
| 78 | |
| 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), |
| 83 | 		 size_t __len)) |
| 84 | __fortify_clang_warning_only_if_bos_lt (__len, __buf, |
| 85 | 					 "readlink called with bigger length " |
| 86 | 					 "than size of destination buffer") |
| 87 | |
| 88 | { |
| 89 | return __glibc_fortify (readlink, __len, sizeof (char), |
| 90 | 			 __glibc_objsize (__buf), |
| 91 | 			 __path, __buf, __len); |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #ifdef __USE_ATFILE |
| 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), |
| 99 | 		 size_t __len)) |
| 100 | __fortify_clang_warning_only_if_bos_lt (__len, __buf, |
| 101 | 					 "readlinkat called with bigger length " |
| 102 | 					 "than size of destination buffer") |
| 103 | { |
| 104 | return __glibc_fortify (readlinkat, __len, sizeof (char), |
| 105 | 			 __glibc_objsize (__buf), |
| 106 | 			 __fd, __path, __buf, __len); |
| 107 | } |
| 108 | #endif |
| 109 | |
| 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") |
| 115 | { |
| 116 | return __glibc_fortify (getcwd, __size, sizeof (char), |
| 117 | 			 __glibc_objsize (__buf), |
| 118 | 			 __buf, __size); |
| 119 | } |
| 120 | |
| 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))) |
| 125 | { |
| 126 | if (__glibc_objsize (__buf) != (size_t) -1) |
| 127 | return __getwd_chk (__buf, __glibc_objsize (__buf)); |
| 128 | return __getwd_warn (__buf); |
| 129 | } |
| 130 | #endif |
| 131 | |
| 132 | __fortify_function __attribute_overloadable__ size_t |
| 133 | __NTH (confstr (int __name, __fortify_clang_overload_arg (char *, ,__buf), |
| 134 | 		size_t __len)) |
| 135 | __fortify_clang_warning_only_if_bos_lt (__len, __buf, |
| 136 | 					 "confstr called with bigger length than " |
| 137 | 					 "size of destination buffer") |
| 138 | { |
| 139 | return __glibc_fortify (confstr, __len, sizeof (char), |
| 140 | 			 __glibc_objsize (__buf), |
| 141 | 			 __name, __buf, __len); |
| 142 | } |
| 143 | |
| 144 | |
| 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") |
| 152 | { |
| 153 | return __glibc_fortify (getgroups, __size, sizeof (__gid_t), |
| 154 | 			 __glibc_objsize (__list), |
| 155 | 			 __size, __list); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | __fortify_function __attribute_overloadable__ int |
| 160 | __NTH (ttyname_r (int __fd, |
| 161 | 		 __fortify_clang_overload_arg (char *, ,__buf), |
| 162 | 		 size_t __buflen)) |
| 163 | __fortify_clang_warning_only_if_bos_lt (__buflen, __buf, |
| 164 | 					 "ttyname_r called with bigger buflen " |
| 165 | 					 "than size of destination buffer") |
| 166 | { |
| 167 | return __glibc_fortify (ttyname_r, __buflen, sizeof (char), |
| 168 | 			 __glibc_objsize (__buf), |
| 169 | 			 __fd, __buf, __buflen); |
| 170 | } |
| 171 | |
| 172 | |
| 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") |
| 179 | { |
| 180 | return __glibc_fortify (getlogin_r, __buflen, sizeof (char), |
| 181 | 			 __glibc_objsize (__buf), |
| 182 | 			 __buf, __buflen); |
| 183 | } |
| 184 | #endif |
| 185 | |
| 186 | |
| 187 | #if defined __USE_MISC || defined __USE_UNIX98 |
| 188 | __fortify_function __attribute_overloadable__ int |
| 189 | __NTH (gethostname (__fortify_clang_overload_arg (char *, ,__buf), |
| 190 | 		 size_t __buflen)) |
| 191 | __fortify_clang_warning_only_if_bos_lt (__buflen, __buf, |
| 192 | 					 "gethostname called with bigger buflen " |
| 193 | 					 "than size of destination buffer") |
| 194 | { |
| 195 | return __glibc_fortify (gethostname, __buflen, sizeof (char), |
| 196 | 			 __glibc_objsize (__buf), |
| 197 | 			 __buf, __buflen); |
| 198 | } |
| 199 | #endif |
| 200 | |
| 201 | |
| 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), |
| 205 | 		 size_t __buflen)) |
| 206 | __fortify_clang_warning_only_if_bos_lt (__buflen, __buf, |
| 207 | 					 "getdomainname called with bigger " |
| 208 | 					 "buflen than size of destination buffer") |
| 209 | { |
| 210 | return __glibc_fortify (getdomainname, __buflen, sizeof (char), |
| 211 | 			 __glibc_objsize (__buf), |
| 212 | 			 __buf, __buflen); |
| 213 | } |
| 214 | #endif |