diff options
| author | Paul Eggert | 2026-02-23 00:20:46 -0800 |
|---|---|---|
| committer | Paul Eggert | 2026-02-23 00:22:17 -0800 |
| commit | ccaa4a07f093428241cbcc81379c3ea3d84b38ee (patch) | |
| tree | 8c3605cd3a89c636a2a23f99257e802f62f3e9ab /lib | |
| parent | 94e4caca6023100192995a206277e24142f0b050 (diff) | |
| download | emacs-ccaa4a07f093428241cbcc81379c3ea3d84b38ee.tar.gz emacs-ccaa4a07f093428241cbcc81379c3ea3d84b38ee.zip | |
Update from Gnulib by running admin/merge-gnulib
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/af_alg.h | 16 | ||||
| -rw-r--r-- | lib/cdefs.h | 250 | ||||
| -rw-r--r-- | lib/gnulib.mk.in | 2 | ||||
| -rw-r--r-- | lib/md5-stream.c | 2 | ||||
| -rw-r--r-- | lib/md5.h | 19 | ||||
| -rw-r--r-- | lib/sha1.c | 12 | ||||
| -rw-r--r-- | lib/sha1.h | 18 | ||||
| -rw-r--r-- | lib/sha256.c | 18 | ||||
| -rw-r--r-- | lib/sha256.h | 26 | ||||
| -rw-r--r-- | lib/sha512.c | 18 | ||||
| -rw-r--r-- | lib/sha512.h | 26 | ||||
| -rw-r--r-- | lib/string.c | 2 | ||||
| -rw-r--r-- | lib/string.in.h | 52 |
13 files changed, 357 insertions, 104 deletions
diff --git a/lib/af_alg.h b/lib/af_alg.h index 1321970f8ee..6272d1ecbbb 100644 --- a/lib/af_alg.h +++ b/lib/af_alg.h | |||
| @@ -58,8 +58,8 @@ extern "C" { | |||
| 58 | If successful, fill RESBLOCK and return 0. | 58 | If successful, fill RESBLOCK and return 0. |
| 59 | Upon failure, return a negated error number. */ | 59 | Upon failure, return a negated error number. */ |
| 60 | int | 60 | int |
| 61 | afalg_buffer (const char *buffer, size_t len, const char *alg, | 61 | afalg_buffer (char const *restrict buffer, size_t len, char const *restrict alg, |
| 62 | void *resblock, ssize_t hashlen); | 62 | void *restrict resblock, ssize_t hashlen); |
| 63 | 63 | ||
| 64 | /* Compute a message digest of data read from STREAM. | 64 | /* Compute a message digest of data read from STREAM. |
| 65 | 65 | ||
| @@ -87,21 +87,21 @@ afalg_buffer (const char *buffer, size_t len, const char *alg, | |||
| 87 | Unless returning 0 or -EIO, restore STREAM's file position so that | 87 | Unless returning 0 or -EIO, restore STREAM's file position so that |
| 88 | the caller can fall back on some other method. */ | 88 | the caller can fall back on some other method. */ |
| 89 | int | 89 | int |
| 90 | afalg_stream (FILE *stream, const char *alg, | 90 | afalg_stream (FILE *restrict stream, char const *restrict alg, |
| 91 | void *resblock, ssize_t hashlen); | 91 | void *restrict resblock, ssize_t hashlen); |
| 92 | 92 | ||
| 93 | # else | 93 | # else |
| 94 | 94 | ||
| 95 | static inline int | 95 | static inline int |
| 96 | afalg_buffer (const char *buffer, size_t len, const char *alg, | 96 | afalg_buffer (char const *restrict buffer, size_t len, char const *restrict alg, |
| 97 | void *resblock, ssize_t hashlen) | 97 | void *restrict resblock, ssize_t hashlen) |
| 98 | { | 98 | { |
| 99 | return -EAFNOSUPPORT; | 99 | return -EAFNOSUPPORT; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | static inline int | 102 | static inline int |
| 103 | afalg_stream (FILE *stream, const char *alg, | 103 | afalg_stream (FILE *restrict stream, char const *restrict alg, |
| 104 | void *resblock, ssize_t hashlen) | 104 | void *restrict resblock, ssize_t hashlen) |
| 105 | { | 105 | { |
| 106 | return -EAFNOSUPPORT; | 106 | return -EAFNOSUPPORT; |
| 107 | } | 107 | } |
diff --git a/lib/cdefs.h b/lib/cdefs.h index 696e65424b7..42024b20e11 100644 --- a/lib/cdefs.h +++ b/lib/cdefs.h | |||
| @@ -24,13 +24,6 @@ | |||
| 24 | # include <features.h> | 24 | # include <features.h> |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | /* The GNU libc does not support any K&R compilers or the traditional mode | ||
| 28 | of ISO C compilers anymore. Check for some of the combinations not | ||
| 29 | supported anymore. */ | ||
| 30 | #if defined __GNUC__ && !defined __STDC__ | ||
| 31 | # error "You need a ISO C conforming compiler to use the glibc headers" | ||
| 32 | #endif | ||
| 33 | |||
| 34 | /* Some user header file might have defined this before. */ | 27 | /* Some user header file might have defined this before. */ |
| 35 | #undef __P | 28 | #undef __P |
| 36 | #undef __PMT | 29 | #undef __PMT |
| @@ -100,6 +93,12 @@ | |||
| 100 | # endif | 93 | # endif |
| 101 | # endif | 94 | # endif |
| 102 | 95 | ||
| 96 | # if __GNUC_PREREQ (4, 3) || __glibc_has_attribute (__cold__) | ||
| 97 | # define __COLD __attribute__ ((__cold__)) | ||
| 98 | # else | ||
| 99 | # define __COLD | ||
| 100 | # endif | ||
| 101 | |||
| 103 | #else /* Not GCC or clang. */ | 102 | #else /* Not GCC or clang. */ |
| 104 | 103 | ||
| 105 | # if (defined __cplusplus \ | 104 | # if (defined __cplusplus \ |
| @@ -112,6 +111,7 @@ | |||
| 112 | # define __THROW | 111 | # define __THROW |
| 113 | # define __THROWNL | 112 | # define __THROWNL |
| 114 | # define __NTH(fct) fct | 113 | # define __NTH(fct) fct |
| 114 | # define __COLD | ||
| 115 | 115 | ||
| 116 | #endif /* GCC || clang. */ | 116 | #endif /* GCC || clang. */ |
| 117 | 117 | ||
| @@ -140,38 +140,47 @@ | |||
| 140 | #endif | 140 | #endif |
| 141 | 141 | ||
| 142 | 142 | ||
| 143 | /* The overloadable attribute was added on clang 2.6. */ | ||
| 144 | #if defined __clang_major__ \ | ||
| 145 | && (__clang_major__ + (__clang_minor__ >= 6) > 2) | ||
| 146 | # define __attribute_overloadable__ __attribute__((__overloadable__)) | ||
| 147 | #else | ||
| 148 | # define __attribute_overloadable__ | ||
| 149 | #endif | ||
| 150 | |||
| 143 | /* Gnulib avoids these definitions, as they don't work on non-glibc platforms. | 151 | /* Gnulib avoids these definitions, as they don't work on non-glibc platforms. |
| 144 | In particular, __bos and __bos0 are defined differently in the Android libc. | 152 | In particular, __bos and __bos0 are defined differently in the Android libc. |
| 145 | */ | 153 | */ |
| 146 | #ifndef __GNULIB_CDEFS | 154 | #ifndef __GNULIB_CDEFS |
| 147 | 155 | ||
| 148 | /* Fortify support. */ | 156 | /* Fortify support. */ |
| 149 | # define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) | 157 | #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) |
| 150 | # define __bos0(ptr) __builtin_object_size (ptr, 0) | 158 | #define __bos0(ptr) __builtin_object_size (ptr, 0) |
| 151 | 159 | ||
| 152 | /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */ | 160 | /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */ |
| 153 | # if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \ | 161 | #if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \ |
| 154 | || __GNUC_PREREQ (12, 0)) | 162 | || __GNUC_PREREQ (12, 0)) |
| 155 | # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0) | 163 | # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0) |
| 156 | # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1) | 164 | # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1) |
| 157 | # else | 165 | #else |
| 158 | # define __glibc_objsize0(__o) __bos0 (__o) | 166 | # define __glibc_objsize0(__o) __bos0 (__o) |
| 159 | # define __glibc_objsize(__o) __bos (__o) | 167 | # define __glibc_objsize(__o) __bos (__o) |
| 160 | # endif | 168 | #endif |
| 161 | 169 | ||
| 170 | #if __USE_FORTIFY_LEVEL > 0 | ||
| 162 | /* Compile time conditions to choose between the regular, _chk and _chk_warn | 171 | /* Compile time conditions to choose between the regular, _chk and _chk_warn |
| 163 | variants. These conditions should get evaluated to constant and optimized | 172 | variants. These conditions should get evaluated to constant and optimized |
| 164 | away. */ | 173 | away. */ |
| 165 | 174 | ||
| 166 | # define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s)) | 175 | #define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s)) |
| 167 | # define __glibc_unsigned_or_positive(__l) \ | 176 | #define __glibc_unsigned_or_positive(__l) \ |
| 168 | ((__typeof (__l)) 0 < (__typeof (__l)) -1 \ | 177 | ((__typeof (__l)) 0 < (__typeof (__l)) -1 \ |
| 169 | || (__builtin_constant_p (__l) && (__l) > 0)) | 178 | || (__builtin_constant_p (__l) && (__l) > 0)) |
| 170 | 179 | ||
| 171 | /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ | 180 | /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ |
| 172 | condition can be folded to a constant and if it is true, or unknown (-1) */ | 181 | condition can be folded to a constant and if it is true, or unknown (-1) */ |
| 173 | # define __glibc_safe_or_unknown_len(__l, __s, __osz) \ | 182 | #define __glibc_safe_or_unknown_len(__l, __s, __osz) \ |
| 174 | ((__osz) == (__SIZE_TYPE__) -1 \ | 183 | ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1) \ |
| 175 | || (__glibc_unsigned_or_positive (__l) \ | 184 | || (__glibc_unsigned_or_positive (__l) \ |
| 176 | && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ | 185 | && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ |
| 177 | (__s), (__osz))) \ | 186 | (__s), (__osz))) \ |
| @@ -180,34 +189,179 @@ | |||
| 180 | /* Conversely, we know at compile time that the length is unsafe if the | 189 | /* Conversely, we know at compile time that the length is unsafe if the |
| 181 | __L * __S <= __OBJSZ condition can be folded to a constant and if it is | 190 | __L * __S <= __OBJSZ condition can be folded to a constant and if it is |
| 182 | false. */ | 191 | false. */ |
| 183 | # define __glibc_unsafe_len(__l, __s, __osz) \ | 192 | #define __glibc_unsafe_len(__l, __s, __osz) \ |
| 184 | (__glibc_unsigned_or_positive (__l) \ | 193 | (__glibc_unsigned_or_positive (__l) \ |
| 185 | && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ | 194 | && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ |
| 186 | __s, __osz)) \ | 195 | __s, __osz)) \ |
| 187 | && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz)) | 196 | && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz)) |
| 188 | 197 | ||
| 198 | /* To correctly instrument the fortify wrapper clang requires the | ||
| 199 | pass_object_size attribute, and the attribute has the restriction that the | ||
| 200 | argument needs to be 'const'. Furthermore, to make it usable with C | ||
| 201 | interfaces, clang provides the overload attribute, which provides a C++ | ||
| 202 | like function overload support. The overloaded fortify wrapper with the | ||
| 203 | pass_object_size attribute has precedence over the default symbol. | ||
| 204 | |||
| 205 | Also, clang does not support __va_arg_pack, so variadic functions are | ||
| 206 | expanded to issue va_arg implementations. The error function must not have | ||
| 207 | bodies (address takes are expanded to nonfortified calls), and with | ||
| 208 | __fortify_function compiler might still create a body with the C++ | ||
| 209 | mangling name (due to the overload attribute). In this case, the function | ||
| 210 | is defined with __fortify_function_error_function macro instead. | ||
| 211 | |||
| 212 | The argument size check is also done with a clang-only attribute, | ||
| 213 | __attribute__ ((__diagnose_if__ (...))), different than gcc which calls | ||
| 214 | symbol_chk_warn alias with uses __warnattr attribute. | ||
| 215 | |||
| 216 | The pass_object_size was added on clang 4.0, __diagnose_if__ on 5.0, | ||
| 217 | and pass_dynamic_object_size on 9.0. */ | ||
| 218 | #if defined __clang_major__ && __clang_major__ >= 5 | ||
| 219 | # define __fortify_use_clang 1 | ||
| 220 | |||
| 221 | # define __fortify_function_error_function static __attribute__((__unused__)) | ||
| 222 | |||
| 223 | # define __fortify_clang_pass_object_size_n(n) \ | ||
| 224 | __attribute__ ((__pass_object_size__ (n))) | ||
| 225 | # define __fortify_clang_pass_object_size0 \ | ||
| 226 | __fortify_clang_pass_object_size_n (0) | ||
| 227 | # define __fortify_clang_pass_object_size \ | ||
| 228 | __fortify_clang_pass_object_size_n (__USE_FORTIFY_LEVEL > 1) | ||
| 229 | |||
| 230 | # if __clang_major__ >= 9 | ||
| 231 | # define __fortify_clang_pass_dynamic_object_size_n(n) \ | ||
| 232 | __attribute__ ((__pass_dynamic_object_size__ (n))) | ||
| 233 | # define __fortify_clang_pass_dynamic_object_size0 \ | ||
| 234 | __fortify_clang_pass_dynamic_object_size_n (0) | ||
| 235 | # define __fortify_clang_pass_dynamic_object_size \ | ||
| 236 | __fortify_clang_pass_dynamic_object_size_n (1) | ||
| 237 | # else | ||
| 238 | # define __fortify_clang_pass_dynamic_object_size_n(n) | ||
| 239 | # define __fortify_clang_pass_dynamic_object_size0 | ||
| 240 | # define __fortify_clang_pass_dynamic_object_size | ||
| 241 | # endif | ||
| 242 | |||
| 243 | # define __fortify_clang_bos_static_lt_impl(bos_val, n, s) \ | ||
| 244 | ((bos_val) != -1ULL && (n) > (bos_val) / (s)) | ||
| 245 | # define __fortify_clang_bos_static_lt2(__n, __e, __s) \ | ||
| 246 | __fortify_clang_bos_static_lt_impl (__bos (__e), __n, __s) | ||
| 247 | # define __fortify_clang_bos_static_lt(__n, __e) \ | ||
| 248 | __fortify_clang_bos_static_lt2 (__n, __e, 1) | ||
| 249 | # define __fortify_clang_bos0_static_lt2(__n, __e, __s) \ | ||
| 250 | __fortify_clang_bos_static_lt_impl (__bos0 (__e), __n, __s) | ||
| 251 | # define __fortify_clang_bos0_static_lt(__n, __e) \ | ||
| 252 | __fortify_clang_bos0_static_lt2 (__n, __e, 1) | ||
| 253 | |||
| 254 | # define __fortify_clang_bosn_args(bos_fn, n, buf, div, complaint) \ | ||
| 255 | (__fortify_clang_bos_static_lt_impl (bos_fn (buf), n, div)), (complaint), \ | ||
| 256 | "warning" | ||
| 257 | |||
| 258 | # define __fortify_clang_warning(__c, __msg) \ | ||
| 259 | __attribute__ ((__diagnose_if__ ((__c), (__msg), "warning"))) | ||
| 260 | # define __fortify_clang_error(__c, __msg) \ | ||
| 261 | __attribute__ ((__diagnose_if__ ((__c), (__msg), "error"))) | ||
| 262 | # define __fortify_clang_warning_only_if_bos0_lt(n, buf, complaint) \ | ||
| 263 | __attribute__ ((__diagnose_if__ \ | ||
| 264 | (__fortify_clang_bosn_args (__bos0, n, buf, 1, complaint)))) | ||
| 265 | # define __fortify_clang_warning_only_if_bos0_lt2(n, buf, div, complaint) \ | ||
| 266 | __attribute__ ((__diagnose_if__ \ | ||
| 267 | (__fortify_clang_bosn_args (__bos0, n, buf, div, complaint)))) | ||
| 268 | # define __fortify_clang_warning_only_if_bos_lt(n, buf, complaint) \ | ||
| 269 | __attribute__ ((__diagnose_if__ \ | ||
| 270 | (__fortify_clang_bosn_args (__bos, n, buf, 1, complaint)))) | ||
| 271 | # define __fortify_clang_warning_only_if_bos_lt2(n, buf, div, complaint) \ | ||
| 272 | __attribute__ ((__diagnose_if__ \ | ||
| 273 | (__fortify_clang_bosn_args (__bos, n, buf, div, complaint)))) | ||
| 274 | |||
| 275 | # define __fortify_clang_prefer_this_overload \ | ||
| 276 | __attribute__ ((enable_if (1, ""))) | ||
| 277 | # define __fortify_clang_unavailable(__msg) \ | ||
| 278 | __attribute__ ((unavailable(__msg))) | ||
| 279 | |||
| 280 | # if __USE_FORTIFY_LEVEL == 3 | ||
| 281 | # define __fortify_clang_overload_arg(__type, __attr, __name) \ | ||
| 282 | __type __attr const __fortify_clang_pass_dynamic_object_size __name | ||
| 283 | # define __fortify_clang_overload_arg0(__type, __attr, __name) \ | ||
| 284 | __type __attr const __fortify_clang_pass_dynamic_object_size0 __name | ||
| 285 | # else | ||
| 286 | # define __fortify_clang_overload_arg(__type, __attr, __name) \ | ||
| 287 | __type __attr const __fortify_clang_pass_object_size __name | ||
| 288 | # define __fortify_clang_overload_arg0(__type, __attr, __name) \ | ||
| 289 | __type __attr const __fortify_clang_pass_object_size0 __name | ||
| 290 | # endif | ||
| 291 | |||
| 292 | # define __fortify_clang_mul_may_overflow(size, n) \ | ||
| 293 | ((size | n) >= (((size_t)1) << (8 * sizeof (size_t) / 2))) | ||
| 294 | |||
| 295 | # define __fortify_clang_size_too_small(__bos, __dest, __len) \ | ||
| 296 | (__bos (__dest) != (size_t) -1 && __bos (__dest) < __len) | ||
| 297 | # define __fortify_clang_warn_if_src_too_large(__dest, __src) \ | ||
| 298 | __fortify_clang_warning (__fortify_clang_size_too_small (__glibc_objsize, \ | ||
| 299 | __dest, \ | ||
| 300 | __builtin_strlen (__src) + 1), \ | ||
| 301 | "destination buffer will always be overflown by source") | ||
| 302 | # define __fortify_clang_warn_if_dest_too_small(__dest, __len) \ | ||
| 303 | __fortify_clang_warning (__fortify_clang_size_too_small (__glibc_objsize, \ | ||
| 304 | __dest, \ | ||
| 305 | __len), \ | ||
| 306 | "function called with bigger length than the destination buffer") | ||
| 307 | # define __fortify_clang_warn_if_dest_too_small0(__dest, __len) \ | ||
| 308 | __fortify_clang_warning (__fortify_clang_size_too_small (__glibc_objsize0, \ | ||
| 309 | __dest, \ | ||
| 310 | __len), \ | ||
| 311 | "function called with bigger length than the destination buffer") | ||
| 312 | #else | ||
| 313 | # define __fortify_use_clang 0 | ||
| 314 | # define __fortify_clang_warning(__c, __msg) | ||
| 315 | # define __fortify_clang_warning_only_if_bos0_lt(__n, __buf, __complaint) | ||
| 316 | # define __fortify_clang_warning_only_if_bos0_lt2(__n, __buf, __div, complaint) | ||
| 317 | # define __fortify_clang_warning_only_if_bos_lt(__n, __buf, __complaint) | ||
| 318 | # define __fortify_clang_warning_only_if_bos_lt2(__n, __buf, div, __complaint) | ||
| 319 | # define __fortify_clang_overload_arg(__type, __attr, __name) \ | ||
| 320 | __type __attr __name | ||
| 321 | # define __fortify_clang_overload_arg0(__type, __attr, __name) \ | ||
| 322 | __fortify_clang_overload_arg (__type, __attr, __name) | ||
| 323 | # define __fortify_clang_warn_if_src_too_large(__dest, __src) | ||
| 324 | # define __fortify_clang_warn_if_dest_too_small(__dest, __len) | ||
| 325 | # define __fortify_clang_warn_if_dest_too_small0(__dest, __len) | ||
| 326 | #endif | ||
| 327 | |||
| 328 | |||
| 189 | /* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be | 329 | /* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be |
| 190 | declared. */ | 330 | declared. */ |
| 191 | 331 | ||
| 332 | #if !__fortify_use_clang | ||
| 192 | # define __glibc_fortify(f, __l, __s, __osz, ...) \ | 333 | # define __glibc_fortify(f, __l, __s, __osz, ...) \ |
| 193 | (__glibc_safe_or_unknown_len (__l, __s, __osz) \ | 334 | (__glibc_safe_or_unknown_len (__l, __s, __osz) \ |
| 194 | ? __ ## f ## _alias (__VA_ARGS__) \ | 335 | ? __ ## f ## _alias (__VA_ARGS__) \ |
| 195 | : (__glibc_unsafe_len (__l, __s, __osz) \ | 336 | : (__glibc_unsafe_len (__l, __s, __osz) \ |
| 196 | ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \ | 337 | ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \ |
| 197 | : __ ## f ## _chk (__VA_ARGS__, __osz))) \ | 338 | : __ ## f ## _chk (__VA_ARGS__, __osz))) |
| 339 | #else | ||
| 340 | # define __glibc_fortify(f, __l, __s, __osz, ...) \ | ||
| 341 | (__osz == (__SIZE_TYPE__) -1) \ | ||
| 342 | ? __ ## f ## _alias (__VA_ARGS__) \ | ||
| 343 | : __ ## f ## _chk (__VA_ARGS__, __osz) | ||
| 344 | #endif | ||
| 198 | 345 | ||
| 199 | /* Fortify function f, where object size argument passed to f is the number of | 346 | /* Fortify function f, where object size argument passed to f is the number of |
| 200 | elements and not total size. */ | 347 | elements and not total size. */ |
| 201 | 348 | ||
| 349 | #if !__fortify_use_clang | ||
| 202 | # define __glibc_fortify_n(f, __l, __s, __osz, ...) \ | 350 | # define __glibc_fortify_n(f, __l, __s, __osz, ...) \ |
| 203 | (__glibc_safe_or_unknown_len (__l, __s, __osz) \ | 351 | (__glibc_safe_or_unknown_len (__l, __s, __osz) \ |
| 204 | ? __ ## f ## _alias (__VA_ARGS__) \ | 352 | ? __ ## f ## _alias (__VA_ARGS__) \ |
| 205 | : (__glibc_unsafe_len (__l, __s, __osz) \ | 353 | : (__glibc_unsafe_len (__l, __s, __osz) \ |
| 206 | ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \ | 354 | ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \ |
| 207 | : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \ | 355 | : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) |
| 208 | 356 | # else | |
| 357 | # define __glibc_fortify_n(f, __l, __s, __osz, ...) \ | ||
| 358 | (__osz == (__SIZE_TYPE__) -1) \ | ||
| 359 | ? __ ## f ## _alias (__VA_ARGS__) \ | ||
| 360 | : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)) | ||
| 209 | #endif | 361 | #endif |
| 210 | 362 | ||
| 363 | #endif /* __USE_FORTIFY_LEVEL > 0 */ | ||
| 364 | #endif /* !__GNULIB_CDEFS */ | ||
| 211 | 365 | ||
| 212 | #if __GNUC_PREREQ (4,3) | 366 | #if __GNUC_PREREQ (4,3) |
| 213 | # define __warnattr(msg) __attribute__((__warning__ (msg))) | 367 | # define __warnattr(msg) __attribute__((__warning__ (msg))) |
| @@ -269,6 +423,14 @@ | |||
| 269 | # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname) | 423 | # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname) |
| 270 | # define __ASMNAME2(prefix, cname) __STRING (prefix) cname | 424 | # define __ASMNAME2(prefix, cname) __STRING (prefix) cname |
| 271 | 425 | ||
| 426 | #ifndef __REDIRECT_FORTIFY | ||
| 427 | #define __REDIRECT_FORTIFY __REDIRECT | ||
| 428 | #endif | ||
| 429 | |||
| 430 | #ifndef __REDIRECT_FORTIFY_NTH | ||
| 431 | #define __REDIRECT_FORTIFY_NTH __REDIRECT_NTH | ||
| 432 | #endif | ||
| 433 | |||
| 272 | /* | 434 | /* |
| 273 | #elif __SOME_OTHER_COMPILER__ | 435 | #elif __SOME_OTHER_COMPILER__ |
| 274 | 436 | ||
| @@ -445,14 +607,14 @@ | |||
| 445 | # define __attribute_artificial__ /* Ignore */ | 607 | # define __attribute_artificial__ /* Ignore */ |
| 446 | #endif | 608 | #endif |
| 447 | 609 | ||
| 448 | /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 | 610 | /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 inline |
| 449 | inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__ | 611 | semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__ or |
| 450 | or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions | 612 | __GNUC_GNU_INLINE__ is not a good enough check for gcc because gcc versions |
| 451 | older than 4.3 may define these macros and still not guarantee GNU inlining | 613 | older than 4.3 may define these macros and still not guarantee GNU inlining |
| 452 | semantics. | 614 | semantics. |
| 453 | 615 | ||
| 454 | clang++ identifies itself as gcc-4.2, but has support for GNU inlining | 616 | clang++ identifies itself as gcc-4.2, but has support for GNU inlining |
| 455 | semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and | 617 | semantics, that can be checked for by using the __GNUC_STDC_INLINE__ and |
| 456 | __GNUC_GNU_INLINE__ macro definitions. */ | 618 | __GNUC_GNU_INLINE__ macro definitions. */ |
| 457 | #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \ | 619 | #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \ |
| 458 | || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \ | 620 | || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \ |
| @@ -577,6 +739,8 @@ | |||
| 577 | # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir | 739 | # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir |
| 578 | # define __LDBL_REDIR_DECL(name) \ | 740 | # define __LDBL_REDIR_DECL(name) \ |
| 579 | extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128")); | 741 | extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128")); |
| 742 | # define __REDIRECT_LDBL(name, proto, alias) \ | ||
| 743 | name proto __asm (__ASMNAME ("__" #alias "ieee128")) | ||
| 580 | 744 | ||
| 581 | /* Alias name defined automatically, with leading underscores. */ | 745 | /* Alias name defined automatically, with leading underscores. */ |
| 582 | # define __LDBL_REDIR2_DECL(name) \ | 746 | # define __LDBL_REDIR2_DECL(name) \ |
| @@ -594,7 +758,6 @@ | |||
| 594 | __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128) | 758 | __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128) |
| 595 | 759 | ||
| 596 | /* Unused. */ | 760 | /* Unused. */ |
| 597 | # define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl | ||
| 598 | # define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth | 761 | # define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth |
| 599 | 762 | ||
| 600 | # else | 763 | # else |
| @@ -666,6 +829,18 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf | |||
| 666 | # define __HAVE_GENERIC_SELECTION 0 | 829 | # define __HAVE_GENERIC_SELECTION 0 |
| 667 | #endif | 830 | #endif |
| 668 | 831 | ||
| 832 | #if __HAVE_GENERIC_SELECTION | ||
| 833 | /* If PTR is a pointer to const, return CALL cast to type CTYPE, | ||
| 834 | otherwise return CALL. Pointers to types with non-const qualifiers | ||
| 835 | are not valid. This should not be defined for C++, as macros are | ||
| 836 | not an appropriate way of implementing such qualifier-generic | ||
| 837 | operations for C++. */ | ||
| 838 | # define __glibc_const_generic(PTR, CTYPE, CALL) \ | ||
| 839 | _Generic (0 ? (PTR) : (void *) 1, \ | ||
| 840 | const void *: (CTYPE) (CALL), \ | ||
| 841 | default: CALL) | ||
| 842 | #endif | ||
| 843 | |||
| 669 | #if __GNUC_PREREQ (10, 0) | 844 | #if __GNUC_PREREQ (10, 0) |
| 670 | /* Designates a 1-based positional argument ref-index of pointer type | 845 | /* Designates a 1-based positional argument ref-index of pointer type |
| 671 | that can be used to access size-index elements of the pointed-to | 846 | that can be used to access size-index elements of the pointed-to |
| @@ -675,10 +850,10 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf | |||
| 675 | # define __attr_access(x) __attribute__ ((__access__ x)) | 850 | # define __attr_access(x) __attribute__ ((__access__ x)) |
| 676 | /* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may | 851 | /* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may |
| 677 | use the access attribute to get object sizes from function definition | 852 | use the access attribute to get object sizes from function definition |
| 678 | arguments, so we can't use them on functions we fortify. Drop the object | 853 | arguments, so we can't use them on functions we fortify. Drop the access |
| 679 | size hints for such functions. */ | 854 | attribute for such functions. */ |
| 680 | # if __USE_FORTIFY_LEVEL == 3 | 855 | # if __USE_FORTIFY_LEVEL == 3 |
| 681 | # define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o))) | 856 | # define __fortified_attr_access(a, o, s) |
| 682 | # else | 857 | # else |
| 683 | # define __fortified_attr_access(a, o, s) __attr_access ((a, o, s)) | 858 | # define __fortified_attr_access(a, o, s) __attr_access ((a, o, s)) |
| 684 | # endif | 859 | # endif |
| @@ -712,4 +887,13 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf | |||
| 712 | # define __attribute_returns_twice__ /* Ignore. */ | 887 | # define __attribute_returns_twice__ /* Ignore. */ |
| 713 | #endif | 888 | #endif |
| 714 | 889 | ||
| 890 | /* Mark struct types as aliasable. Restricted to compilers that | ||
| 891 | support forward declarations of structs in the presence of the | ||
| 892 | attribute. */ | ||
| 893 | #if __GNUC_PREREQ (7, 1) || defined __clang__ | ||
| 894 | # define __attribute_struct_may_alias__ __attribute__ ((__may_alias__)) | ||
| 895 | #else | ||
| 896 | # define __attribute_struct_may_alias__ | ||
| 897 | #endif | ||
| 898 | |||
| 715 | #endif /* sys/cdefs.h */ | 899 | #endif /* sys/cdefs.h */ |
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 6b7889cf835..d7203c16fde 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in | |||
| @@ -635,6 +635,7 @@ GL_GNULIB_STRNCAT = @GL_GNULIB_STRNCAT@ | |||
| 635 | GL_GNULIB_STRNCPY = @GL_GNULIB_STRNCPY@ | 635 | GL_GNULIB_STRNCPY = @GL_GNULIB_STRNCPY@ |
| 636 | GL_GNULIB_STRNDUP = @GL_GNULIB_STRNDUP@ | 636 | GL_GNULIB_STRNDUP = @GL_GNULIB_STRNDUP@ |
| 637 | GL_GNULIB_STRNLEN = @GL_GNULIB_STRNLEN@ | 637 | GL_GNULIB_STRNLEN = @GL_GNULIB_STRNLEN@ |
| 638 | GL_GNULIB_STRNUL = @GL_GNULIB_STRNUL@ | ||
| 638 | GL_GNULIB_STRPBRK = @GL_GNULIB_STRPBRK@ | 639 | GL_GNULIB_STRPBRK = @GL_GNULIB_STRPBRK@ |
| 639 | GL_GNULIB_STRPTIME = @GL_GNULIB_STRPTIME@ | 640 | GL_GNULIB_STRPTIME = @GL_GNULIB_STRPTIME@ |
| 640 | GL_GNULIB_STRSEP = @GL_GNULIB_STRSEP@ | 641 | GL_GNULIB_STRSEP = @GL_GNULIB_STRSEP@ |
| @@ -3765,6 +3766,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H | |||
| 3765 | -e 's/@''GNULIB_STRNCPY''@/$(GL_GNULIB_STRNCPY)/g' \ | 3766 | -e 's/@''GNULIB_STRNCPY''@/$(GL_GNULIB_STRNCPY)/g' \ |
| 3766 | -e 's/@''GNULIB_STRNDUP''@/$(GL_GNULIB_STRNDUP)/g' \ | 3767 | -e 's/@''GNULIB_STRNDUP''@/$(GL_GNULIB_STRNDUP)/g' \ |
| 3767 | -e 's/@''GNULIB_STRNLEN''@/$(GL_GNULIB_STRNLEN)/g' \ | 3768 | -e 's/@''GNULIB_STRNLEN''@/$(GL_GNULIB_STRNLEN)/g' \ |
| 3769 | -e 's/@''GNULIB_STRNUL''@/$(GL_GNULIB_STRNUL)/g' \ | ||
| 3768 | -e 's/@''GNULIB_STRPBRK''@/$(GL_GNULIB_STRPBRK)/g' \ | 3770 | -e 's/@''GNULIB_STRPBRK''@/$(GL_GNULIB_STRPBRK)/g' \ |
| 3769 | -e 's/@''GNULIB_STRSEP''@/$(GL_GNULIB_STRSEP)/g' \ | 3771 | -e 's/@''GNULIB_STRSEP''@/$(GL_GNULIB_STRSEP)/g' \ |
| 3770 | -e 's/@''GNULIB_STRSTR''@/$(GL_GNULIB_STRSTR)/g' \ | 3772 | -e 's/@''GNULIB_STRSTR''@/$(GL_GNULIB_STRSTR)/g' \ |
diff --git a/lib/md5-stream.c b/lib/md5-stream.c index 96b92374c1d..ffe077f52ab 100644 --- a/lib/md5-stream.c +++ b/lib/md5-stream.c | |||
| @@ -63,7 +63,7 @@ md5_stream (FILE *stream, void *resblock) | |||
| 63 | case -EIO: return 1; | 63 | case -EIO: return 1; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | char *buffer = malloc (BLOCKSIZE + 72); | 66 | char *buffer = malloc (BLOCKSIZE); |
| 67 | if (!buffer) | 67 | if (!buffer) |
| 68 | return 1; | 68 | return 1; |
| 69 | 69 | ||
| @@ -121,28 +121,30 @@ extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW; | |||
| 121 | initialization function update the context for the next LEN bytes | 121 | initialization function update the context for the next LEN bytes |
| 122 | starting at BUFFER. | 122 | starting at BUFFER. |
| 123 | It is necessary that LEN is a multiple of 64!!! */ | 123 | It is necessary that LEN is a multiple of 64!!! */ |
| 124 | extern void __md5_process_block (const void *buffer, size_t len, | 124 | extern void __md5_process_block (void const *restrict buffer, size_t len, |
| 125 | struct md5_ctx *ctx) __THROW; | 125 | struct md5_ctx *restrict ctx) __THROW; |
| 126 | 126 | ||
| 127 | /* Starting with the result of former calls of this function (or the | 127 | /* Starting with the result of former calls of this function (or the |
| 128 | initialization function update the context for the next LEN bytes | 128 | initialization function update the context for the next LEN bytes |
| 129 | starting at BUFFER. | 129 | starting at BUFFER. |
| 130 | It is NOT required that LEN is a multiple of 64. */ | 130 | It is NOT required that LEN is a multiple of 64. */ |
| 131 | extern void __md5_process_bytes (const void *buffer, size_t len, | 131 | extern void __md5_process_bytes (void const *restrict buffer, size_t len, |
| 132 | struct md5_ctx *ctx) __THROW; | 132 | struct md5_ctx *restrict ctx) __THROW; |
| 133 | 133 | ||
| 134 | /* Process the remaining bytes in the buffer and put result from CTX | 134 | /* Process the remaining bytes in the buffer and put result from CTX |
| 135 | in first 16 bytes following RESBUF. The result is always in little | 135 | in first 16 bytes following RESBUF. The result is always in little |
| 136 | endian byte order, so that a byte-wise output yields to the wanted | 136 | endian byte order, so that a byte-wise output yields to the wanted |
| 137 | ASCII representation of the message digest. */ | 137 | ASCII representation of the message digest. */ |
| 138 | extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *restrict resbuf) | 138 | extern void *__md5_finish_ctx (struct md5_ctx *restrict ctx, |
| 139 | void *restrict resbuf) | ||
| 139 | __THROW; | 140 | __THROW; |
| 140 | 141 | ||
| 141 | 142 | ||
| 142 | /* Put result from CTX in first 16 bytes following RESBUF. The result is | 143 | /* Put result from CTX in first 16 bytes following RESBUF. The result is |
| 143 | always in little endian byte order, so that a byte-wise output yields | 144 | always in little endian byte order, so that a byte-wise output yields |
| 144 | to the wanted ASCII representation of the message digest. */ | 145 | to the wanted ASCII representation of the message digest. */ |
| 145 | extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *restrict resbuf) | 146 | extern void *__md5_read_ctx (struct md5_ctx const *restrict ctx, |
| 147 | void *restrict resbuf) | ||
| 146 | __THROW; | 148 | __THROW; |
| 147 | 149 | ||
| 148 | 150 | ||
| @@ -150,7 +152,7 @@ extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *restrict resbuf) | |||
| 150 | result is always in little endian byte order, so that a byte-wise | 152 | result is always in little endian byte order, so that a byte-wise |
| 151 | output yields to the wanted ASCII representation of the message | 153 | output yields to the wanted ASCII representation of the message |
| 152 | digest. */ | 154 | digest. */ |
| 153 | extern void *__md5_buffer (const char *buffer, size_t len, | 155 | extern void *__md5_buffer (char const *restrict buffer, size_t len, |
| 154 | void *restrict resblock) __THROW; | 156 | void *restrict resblock) __THROW; |
| 155 | 157 | ||
| 156 | # endif | 158 | # endif |
| @@ -161,7 +163,8 @@ extern void *__md5_buffer (const char *buffer, size_t len, | |||
| 161 | The case that the last operation on STREAM was an 'ungetc' is not supported. | 163 | The case that the last operation on STREAM was an 'ungetc' is not supported. |
| 162 | The resulting message digest number will be written into the 16 bytes | 164 | The resulting message digest number will be written into the 16 bytes |
| 163 | beginning at RESBLOCK. */ | 165 | beginning at RESBLOCK. */ |
| 164 | extern int __md5_stream (FILE *stream, void *resblock) __THROW; | 166 | extern int __md5_stream (FILE *restrict stream, void *restrict resblock) |
| 167 | __THROW; | ||
| 165 | 168 | ||
| 166 | 169 | ||
| 167 | # ifdef __cplusplus | 170 | # ifdef __cplusplus |
diff --git a/lib/sha1.c b/lib/sha1.c index f41bda875db..bb7aa2af293 100644 --- a/lib/sha1.c +++ b/lib/sha1.c | |||
| @@ -74,7 +74,7 @@ set_uint32 (char *cp, uint32_t v) | |||
| 74 | /* Put result from CTX in first 20 bytes following RESBUF. The result | 74 | /* Put result from CTX in first 20 bytes following RESBUF. The result |
| 75 | must be in little endian byte order. */ | 75 | must be in little endian byte order. */ |
| 76 | void * | 76 | void * |
| 77 | sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf) | 77 | sha1_read_ctx (struct sha1_ctx const *restrict ctx, void *restrict resbuf) |
| 78 | { | 78 | { |
| 79 | char *r = resbuf; | 79 | char *r = resbuf; |
| 80 | set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A)); | 80 | set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A)); |
| @@ -89,7 +89,7 @@ sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf) | |||
| 89 | /* Process the remaining bytes in the internal buffer and the usual | 89 | /* Process the remaining bytes in the internal buffer and the usual |
| 90 | prolog according to the standard and write the result to RESBUF. */ | 90 | prolog according to the standard and write the result to RESBUF. */ |
| 91 | void * | 91 | void * |
| 92 | sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf) | 92 | sha1_finish_ctx (struct sha1_ctx *restrict ctx, void *restrict resbuf) |
| 93 | { | 93 | { |
| 94 | /* Take yet unprocessed bytes into account. */ | 94 | /* Take yet unprocessed bytes into account. */ |
| 95 | uint32_t bytes = ctx->buflen; | 95 | uint32_t bytes = ctx->buflen; |
| @@ -117,7 +117,7 @@ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf) | |||
| 117 | output yields to the wanted ASCII representation of the message | 117 | output yields to the wanted ASCII representation of the message |
| 118 | digest. */ | 118 | digest. */ |
| 119 | void * | 119 | void * |
| 120 | sha1_buffer (const char *buffer, size_t len, void *resblock) | 120 | sha1_buffer (char const *restrict buffer, size_t len, void *restrict resblock) |
| 121 | { | 121 | { |
| 122 | struct sha1_ctx ctx; | 122 | struct sha1_ctx ctx; |
| 123 | 123 | ||
| @@ -132,7 +132,8 @@ sha1_buffer (const char *buffer, size_t len, void *resblock) | |||
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | void | 134 | void |
| 135 | sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) | 135 | sha1_process_bytes (void const *restrict buffer, size_t len, |
| 136 | struct sha1_ctx *restrict ctx) | ||
| 136 | { | 137 | { |
| 137 | /* When we already have some bits in our internal buffer concatenate | 138 | /* When we already have some bits in our internal buffer concatenate |
| 138 | both inputs first. */ | 139 | both inputs first. */ |
| @@ -219,7 +220,8 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) | |||
| 219 | Most of this code comes from GnuPG's cipher/sha1.c. */ | 220 | Most of this code comes from GnuPG's cipher/sha1.c. */ |
| 220 | 221 | ||
| 221 | void | 222 | void |
| 222 | sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx) | 223 | sha1_process_block (void const *restrict buffer, size_t len, |
| 224 | struct sha1_ctx *restrict ctx) | ||
| 223 | { | 225 | { |
| 224 | const uint32_t *words = buffer; | 226 | const uint32_t *words = buffer; |
| 225 | size_t nwords = len / sizeof (uint32_t); | 227 | size_t nwords = len / sizeof (uint32_t); |
diff --git a/lib/sha1.h b/lib/sha1.h index a267d46ab4c..444902cb28e 100644 --- a/lib/sha1.h +++ b/lib/sha1.h | |||
| @@ -79,34 +79,36 @@ extern void sha1_init_ctx (struct sha1_ctx *ctx); | |||
| 79 | initialization function update the context for the next LEN bytes | 79 | initialization function update the context for the next LEN bytes |
| 80 | starting at BUFFER. | 80 | starting at BUFFER. |
| 81 | It is necessary that LEN is a multiple of 64!!! */ | 81 | It is necessary that LEN is a multiple of 64!!! */ |
| 82 | extern void sha1_process_block (const void *buffer, size_t len, | 82 | extern void sha1_process_block (void const *restrict buffer, size_t len, |
| 83 | struct sha1_ctx *ctx); | 83 | struct sha1_ctx *restrict ctx); |
| 84 | 84 | ||
| 85 | /* Starting with the result of former calls of this function (or the | 85 | /* Starting with the result of former calls of this function (or the |
| 86 | initialization function update the context for the next LEN bytes | 86 | initialization function update the context for the next LEN bytes |
| 87 | starting at BUFFER. | 87 | starting at BUFFER. |
| 88 | It is NOT required that LEN is a multiple of 64. */ | 88 | It is NOT required that LEN is a multiple of 64. */ |
| 89 | extern void sha1_process_bytes (const void *buffer, size_t len, | 89 | extern void sha1_process_bytes (void const *restrict buffer, size_t len, |
| 90 | struct sha1_ctx *ctx); | 90 | struct sha1_ctx *restrict ctx); |
| 91 | 91 | ||
| 92 | /* Process the remaining bytes in the buffer and put result from CTX | 92 | /* Process the remaining bytes in the buffer and put result from CTX |
| 93 | in first 20 bytes following RESBUF. The result is always in little | 93 | in first 20 bytes following RESBUF. The result is always in little |
| 94 | endian byte order, so that a byte-wise output yields to the wanted | 94 | endian byte order, so that a byte-wise output yields to the wanted |
| 95 | ASCII representation of the message digest. */ | 95 | ASCII representation of the message digest. */ |
| 96 | extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *restrict resbuf); | 96 | extern void *sha1_finish_ctx (struct sha1_ctx *restrict ctx, |
| 97 | void *restrict resbuf); | ||
| 97 | 98 | ||
| 98 | 99 | ||
| 99 | /* Put result from CTX in first 20 bytes following RESBUF. The result is | 100 | /* Put result from CTX in first 20 bytes following RESBUF. The result is |
| 100 | always in little endian byte order, so that a byte-wise output yields | 101 | always in little endian byte order, so that a byte-wise output yields |
| 101 | to the wanted ASCII representation of the message digest. */ | 102 | to the wanted ASCII representation of the message digest. */ |
| 102 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *restrict resbuf); | 103 | extern void *sha1_read_ctx (struct sha1_ctx const *restrict ctx, |
| 104 | void *restrict resbuf); | ||
| 103 | 105 | ||
| 104 | 106 | ||
| 105 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The | 107 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The |
| 106 | result is always in little endian byte order, so that a byte-wise | 108 | result is always in little endian byte order, so that a byte-wise |
| 107 | output yields to the wanted ASCII representation of the message | 109 | output yields to the wanted ASCII representation of the message |
| 108 | digest. */ | 110 | digest. */ |
| 109 | extern void *sha1_buffer (const char *buffer, size_t len, | 111 | extern void *sha1_buffer (char const *restrict buffer, size_t len, |
| 110 | void *restrict resblock); | 112 | void *restrict resblock); |
| 111 | 113 | ||
| 112 | # endif | 114 | # endif |
| @@ -117,7 +119,7 @@ extern void *sha1_buffer (const char *buffer, size_t len, | |||
| 117 | The case that the last operation on STREAM was an 'ungetc' is not supported. | 119 | The case that the last operation on STREAM was an 'ungetc' is not supported. |
| 118 | The resulting message digest number will be written into the 20 bytes | 120 | The resulting message digest number will be written into the 20 bytes |
| 119 | beginning at RESBLOCK. */ | 121 | beginning at RESBLOCK. */ |
| 120 | extern int sha1_stream (FILE *stream, void *resblock); | 122 | extern int sha1_stream (FILE *restrict stream, void *restrict resblock); |
| 121 | 123 | ||
| 122 | 124 | ||
| 123 | # ifdef __cplusplus | 125 | # ifdef __cplusplus |
diff --git a/lib/sha256.c b/lib/sha256.c index bada2d07171..115b288e467 100644 --- a/lib/sha256.c +++ b/lib/sha256.c | |||
| @@ -94,7 +94,7 @@ set_uint32 (char *cp, uint32_t v) | |||
| 94 | /* Put result from CTX in first 32 bytes following RESBUF. | 94 | /* Put result from CTX in first 32 bytes following RESBUF. |
| 95 | The result must be in little endian byte order. */ | 95 | The result must be in little endian byte order. */ |
| 96 | void * | 96 | void * |
| 97 | sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf) | 97 | sha256_read_ctx (struct sha256_ctx const *restrict ctx, void *restrict resbuf) |
| 98 | { | 98 | { |
| 99 | char *r = resbuf; | 99 | char *r = resbuf; |
| 100 | 100 | ||
| @@ -105,7 +105,7 @@ sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf) | |||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | void * | 107 | void * |
| 108 | sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf) | 108 | sha224_read_ctx (struct sha256_ctx const *restrict ctx, void *restrict resbuf) |
| 109 | { | 109 | { |
| 110 | char *r = resbuf; | 110 | char *r = resbuf; |
| 111 | 111 | ||
| @@ -144,14 +144,14 @@ sha256_conclude_ctx (struct sha256_ctx *ctx) | |||
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | void * | 146 | void * |
| 147 | sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf) | 147 | sha256_finish_ctx (struct sha256_ctx *restrict ctx, void *restrict resbuf) |
| 148 | { | 148 | { |
| 149 | sha256_conclude_ctx (ctx); | 149 | sha256_conclude_ctx (ctx); |
| 150 | return sha256_read_ctx (ctx, resbuf); | 150 | return sha256_read_ctx (ctx, resbuf); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | void * | 153 | void * |
| 154 | sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf) | 154 | sha224_finish_ctx (struct sha256_ctx *restrict ctx, void *restrict resbuf) |
| 155 | { | 155 | { |
| 156 | sha256_conclude_ctx (ctx); | 156 | sha256_conclude_ctx (ctx); |
| 157 | return sha224_read_ctx (ctx, resbuf); | 157 | return sha224_read_ctx (ctx, resbuf); |
| @@ -162,7 +162,7 @@ sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf) | |||
| 162 | output yields to the wanted ASCII representation of the message | 162 | output yields to the wanted ASCII representation of the message |
| 163 | digest. */ | 163 | digest. */ |
| 164 | void * | 164 | void * |
| 165 | sha256_buffer (const char *buffer, size_t len, void *resblock) | 165 | sha256_buffer (char const *restrict buffer, size_t len, void *restrict resblock) |
| 166 | { | 166 | { |
| 167 | struct sha256_ctx ctx; | 167 | struct sha256_ctx ctx; |
| 168 | 168 | ||
| @@ -177,7 +177,7 @@ sha256_buffer (const char *buffer, size_t len, void *resblock) | |||
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | void * | 179 | void * |
| 180 | sha224_buffer (const char *buffer, size_t len, void *resblock) | 180 | sha224_buffer (char const *restrict buffer, size_t len, void *restrict resblock) |
| 181 | { | 181 | { |
| 182 | struct sha256_ctx ctx; | 182 | struct sha256_ctx ctx; |
| 183 | 183 | ||
| @@ -192,7 +192,8 @@ sha224_buffer (const char *buffer, size_t len, void *resblock) | |||
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | void | 194 | void |
| 195 | sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) | 195 | sha256_process_bytes (void const *restrict buffer, size_t len, |
| 196 | struct sha256_ctx *restrict ctx) | ||
| 196 | { | 197 | { |
| 197 | /* When we already have some bits in our internal buffer concatenate | 198 | /* When we already have some bits in our internal buffer concatenate |
| 198 | both inputs first. */ | 199 | both inputs first. */ |
| @@ -292,7 +293,8 @@ static const uint32_t sha256_round_constants[64] = { | |||
| 292 | Most of this code comes from GnuPG's cipher/sha1.c. */ | 293 | Most of this code comes from GnuPG's cipher/sha1.c. */ |
| 293 | 294 | ||
| 294 | void | 295 | void |
| 295 | sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) | 296 | sha256_process_block (void const *restrict buffer, size_t len, |
| 297 | struct sha256_ctx *restrict ctx) | ||
| 296 | { | 298 | { |
| 297 | const uint32_t *words = buffer; | 299 | const uint32_t *words = buffer; |
| 298 | size_t nwords = len / sizeof (uint32_t); | 300 | size_t nwords = len / sizeof (uint32_t); |
diff --git a/lib/sha256.h b/lib/sha256.h index db80ea5e357..867befdd5d3 100644 --- a/lib/sha256.h +++ b/lib/sha256.h | |||
| @@ -78,30 +78,32 @@ extern void sha224_init_ctx (struct sha256_ctx *ctx); | |||
| 78 | initialization function update the context for the next LEN bytes | 78 | initialization function update the context for the next LEN bytes |
| 79 | starting at BUFFER. | 79 | starting at BUFFER. |
| 80 | It is necessary that LEN is a multiple of 64!!! */ | 80 | It is necessary that LEN is a multiple of 64!!! */ |
| 81 | extern void sha256_process_block (const void *buffer, size_t len, | 81 | extern void sha256_process_block (void const *restrict buffer, size_t len, |
| 82 | struct sha256_ctx *ctx); | 82 | struct sha256_ctx *restrict ctx); |
| 83 | 83 | ||
| 84 | /* Starting with the result of former calls of this function (or the | 84 | /* Starting with the result of former calls of this function (or the |
| 85 | initialization function update the context for the next LEN bytes | 85 | initialization function update the context for the next LEN bytes |
| 86 | starting at BUFFER. | 86 | starting at BUFFER. |
| 87 | It is NOT required that LEN is a multiple of 64. */ | 87 | It is NOT required that LEN is a multiple of 64. */ |
| 88 | extern void sha256_process_bytes (const void *buffer, size_t len, | 88 | extern void sha256_process_bytes (void const *restrict buffer, size_t len, |
| 89 | struct sha256_ctx *ctx); | 89 | struct sha256_ctx *restrict ctx); |
| 90 | 90 | ||
| 91 | /* Process the remaining bytes in the buffer and put result from CTX | 91 | /* Process the remaining bytes in the buffer and put result from CTX |
| 92 | in first 32 (28) bytes following RESBUF. The result is always in little | 92 | in first 32 (28) bytes following RESBUF. The result is always in little |
| 93 | endian byte order, so that a byte-wise output yields to the wanted | 93 | endian byte order, so that a byte-wise output yields to the wanted |
| 94 | ASCII representation of the message digest. */ | 94 | ASCII representation of the message digest. */ |
| 95 | extern void *sha256_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf); | 95 | extern void *sha256_finish_ctx (struct sha256_ctx *restrict ctx, |
| 96 | extern void *sha224_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf); | 96 | void *restrict resbuf); |
| 97 | extern void *sha224_finish_ctx (struct sha256_ctx *restrict ctx, | ||
| 98 | void *restrict resbuf); | ||
| 97 | 99 | ||
| 98 | 100 | ||
| 99 | /* Put result from CTX in first 32 (28) bytes following RESBUF. The result is | 101 | /* Put result from CTX in first 32 (28) bytes following RESBUF. The result is |
| 100 | always in little endian byte order, so that a byte-wise output yields | 102 | always in little endian byte order, so that a byte-wise output yields |
| 101 | to the wanted ASCII representation of the message digest. */ | 103 | to the wanted ASCII representation of the message digest. */ |
| 102 | extern void *sha256_read_ctx (const struct sha256_ctx *ctx, | 104 | extern void *sha256_read_ctx (struct sha256_ctx const *restrict ctx, |
| 103 | void *restrict resbuf); | 105 | void *restrict resbuf); |
| 104 | extern void *sha224_read_ctx (const struct sha256_ctx *ctx, | 106 | extern void *sha224_read_ctx (struct sha256_ctx const *restrict ctx, |
| 105 | void *restrict resbuf); | 107 | void *restrict resbuf); |
| 106 | 108 | ||
| 107 | 109 | ||
| @@ -109,9 +111,9 @@ extern void *sha224_read_ctx (const struct sha256_ctx *ctx, | |||
| 109 | The result is always in little endian byte order, so that a byte-wise | 111 | The result is always in little endian byte order, so that a byte-wise |
| 110 | output yields to the wanted ASCII representation of the message | 112 | output yields to the wanted ASCII representation of the message |
| 111 | digest. */ | 113 | digest. */ |
| 112 | extern void *sha256_buffer (const char *buffer, size_t len, | 114 | extern void *sha256_buffer (char const *restrict buffer, size_t len, |
| 113 | void *restrict resblock); | 115 | void *restrict resblock); |
| 114 | extern void *sha224_buffer (const char *buffer, size_t len, | 116 | extern void *sha224_buffer (char const *restrict buffer, size_t len, |
| 115 | void *restrict resblock); | 117 | void *restrict resblock); |
| 116 | 118 | ||
| 117 | # endif | 119 | # endif |
| @@ -122,8 +124,8 @@ extern void *sha224_buffer (const char *buffer, size_t len, | |||
| 122 | The case that the last operation on STREAM was an 'ungetc' is not supported. | 124 | The case that the last operation on STREAM was an 'ungetc' is not supported. |
| 123 | The resulting message digest number will be written into the 32 (28) bytes | 125 | The resulting message digest number will be written into the 32 (28) bytes |
| 124 | beginning at RESBLOCK. */ | 126 | beginning at RESBLOCK. */ |
| 125 | extern int sha256_stream (FILE *stream, void *resblock); | 127 | extern int sha256_stream (FILE *restrict stream, void *restrict resblock); |
| 126 | extern int sha224_stream (FILE *stream, void *resblock); | 128 | extern int sha224_stream (FILE *restrict stream, void *restrict resblock); |
| 127 | 129 | ||
| 128 | 130 | ||
| 129 | # ifdef __cplusplus | 131 | # ifdef __cplusplus |
diff --git a/lib/sha512.c b/lib/sha512.c index a8c6484c2ed..4a213f8accc 100644 --- a/lib/sha512.c +++ b/lib/sha512.c | |||
| @@ -94,7 +94,7 @@ set_uint64 (char *cp, u64 v) | |||
| 94 | /* Put result from CTX in first 64 bytes following RESBUF. | 94 | /* Put result from CTX in first 64 bytes following RESBUF. |
| 95 | The result must be in little endian byte order. */ | 95 | The result must be in little endian byte order. */ |
| 96 | void * | 96 | void * |
| 97 | sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf) | 97 | sha512_read_ctx (struct sha512_ctx const *restrict ctx, void *restrict resbuf) |
| 98 | { | 98 | { |
| 99 | char *r = resbuf; | 99 | char *r = resbuf; |
| 100 | 100 | ||
| @@ -105,7 +105,7 @@ sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf) | |||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | void * | 107 | void * |
| 108 | sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf) | 108 | sha384_read_ctx (struct sha512_ctx const *restrict ctx, void *restrict resbuf) |
| 109 | { | 109 | { |
| 110 | char *r = resbuf; | 110 | char *r = resbuf; |
| 111 | 111 | ||
| @@ -145,14 +145,14 @@ sha512_conclude_ctx (struct sha512_ctx *ctx) | |||
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | void * | 147 | void * |
| 148 | sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf) | 148 | sha512_finish_ctx (struct sha512_ctx *restrict ctx, void *restrict resbuf) |
| 149 | { | 149 | { |
| 150 | sha512_conclude_ctx (ctx); | 150 | sha512_conclude_ctx (ctx); |
| 151 | return sha512_read_ctx (ctx, resbuf); | 151 | return sha512_read_ctx (ctx, resbuf); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | void * | 154 | void * |
| 155 | sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf) | 155 | sha384_finish_ctx (struct sha512_ctx *restrict ctx, void *restrict resbuf) |
| 156 | { | 156 | { |
| 157 | sha512_conclude_ctx (ctx); | 157 | sha512_conclude_ctx (ctx); |
| 158 | return sha384_read_ctx (ctx, resbuf); | 158 | return sha384_read_ctx (ctx, resbuf); |
| @@ -163,7 +163,7 @@ sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf) | |||
| 163 | output yields to the wanted ASCII representation of the message | 163 | output yields to the wanted ASCII representation of the message |
| 164 | digest. */ | 164 | digest. */ |
| 165 | void * | 165 | void * |
| 166 | sha512_buffer (const char *buffer, size_t len, void *resblock) | 166 | sha512_buffer (char const *restrict buffer, size_t len, void *restrict resblock) |
| 167 | { | 167 | { |
| 168 | struct sha512_ctx ctx; | 168 | struct sha512_ctx ctx; |
| 169 | 169 | ||
| @@ -178,7 +178,7 @@ sha512_buffer (const char *buffer, size_t len, void *resblock) | |||
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | void * | 180 | void * |
| 181 | sha384_buffer (const char *buffer, size_t len, void *resblock) | 181 | sha384_buffer (char const *restrict buffer, size_t len, void *restrict resblock) |
| 182 | { | 182 | { |
| 183 | struct sha512_ctx ctx; | 183 | struct sha512_ctx ctx; |
| 184 | 184 | ||
| @@ -193,7 +193,8 @@ sha384_buffer (const char *buffer, size_t len, void *resblock) | |||
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | void | 195 | void |
| 196 | sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) | 196 | sha512_process_bytes (void const *restrict buffer, size_t len, |
| 197 | struct sha512_ctx *restrict ctx) | ||
| 197 | { | 198 | { |
| 198 | /* When we already have some bits in our internal buffer concatenate | 199 | /* When we already have some bits in our internal buffer concatenate |
| 199 | both inputs first. */ | 200 | both inputs first. */ |
| @@ -317,7 +318,8 @@ static u64 const sha512_round_constants[80] = { | |||
| 317 | Most of this code comes from GnuPG's cipher/sha1.c. */ | 318 | Most of this code comes from GnuPG's cipher/sha1.c. */ |
| 318 | 319 | ||
| 319 | void | 320 | void |
| 320 | sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) | 321 | sha512_process_block (void const *restrict buffer, size_t len, |
| 322 | struct sha512_ctx *restrict ctx) | ||
| 321 | { | 323 | { |
| 322 | u64 const *words = buffer; | 324 | u64 const *words = buffer; |
| 323 | u64 const *endp = words + len / sizeof (u64); | 325 | u64 const *endp = words + len / sizeof (u64); |
diff --git a/lib/sha512.h b/lib/sha512.h index aedd9c8e210..6b9cf58da11 100644 --- a/lib/sha512.h +++ b/lib/sha512.h | |||
| @@ -78,22 +78,24 @@ extern void sha384_init_ctx (struct sha512_ctx *ctx); | |||
| 78 | initialization function update the context for the next LEN bytes | 78 | initialization function update the context for the next LEN bytes |
| 79 | starting at BUFFER. | 79 | starting at BUFFER. |
| 80 | It is necessary that LEN is a multiple of 128!!! */ | 80 | It is necessary that LEN is a multiple of 128!!! */ |
| 81 | extern void sha512_process_block (const void *buffer, size_t len, | 81 | extern void sha512_process_block (void const *restrict buffer, size_t len, |
| 82 | struct sha512_ctx *ctx); | 82 | struct sha512_ctx *restrict ctx); |
| 83 | 83 | ||
| 84 | /* Starting with the result of former calls of this function (or the | 84 | /* Starting with the result of former calls of this function (or the |
| 85 | initialization function update the context for the next LEN bytes | 85 | initialization function update the context for the next LEN bytes |
| 86 | starting at BUFFER. | 86 | starting at BUFFER. |
| 87 | It is NOT required that LEN is a multiple of 128. */ | 87 | It is NOT required that LEN is a multiple of 128. */ |
| 88 | extern void sha512_process_bytes (const void *buffer, size_t len, | 88 | extern void sha512_process_bytes (void const *restrict buffer, size_t len, |
| 89 | struct sha512_ctx *ctx); | 89 | struct sha512_ctx *restrict ctx); |
| 90 | 90 | ||
| 91 | /* Process the remaining bytes in the buffer and put result from CTX | 91 | /* Process the remaining bytes in the buffer and put result from CTX |
| 92 | in first 64 (48) bytes following RESBUF. The result is always in little | 92 | in first 64 (48) bytes following RESBUF. The result is always in little |
| 93 | endian byte order, so that a byte-wise output yields to the wanted | 93 | endian byte order, so that a byte-wise output yields to the wanted |
| 94 | ASCII representation of the message digest. */ | 94 | ASCII representation of the message digest. */ |
| 95 | extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *restrict resbuf); | 95 | extern void *sha512_finish_ctx (struct sha512_ctx *restrict ctx, |
| 96 | extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *restrict resbuf); | 96 | void *restrict resbuf); |
| 97 | extern void *sha384_finish_ctx (struct sha512_ctx *restrict ctx, | ||
| 98 | void *restrict resbuf); | ||
| 97 | 99 | ||
| 98 | 100 | ||
| 99 | /* Put result from CTX in first 64 (48) bytes following RESBUF. The result is | 101 | /* Put result from CTX in first 64 (48) bytes following RESBUF. The result is |
| @@ -102,9 +104,9 @@ extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *restrict resbuf); | |||
| 102 | 104 | ||
| 103 | IMPORTANT: On some systems it is required that RESBUF is correctly | 105 | IMPORTANT: On some systems it is required that RESBUF is correctly |
| 104 | aligned for a 32 bits value. */ | 106 | aligned for a 32 bits value. */ |
| 105 | extern void *sha512_read_ctx (const struct sha512_ctx *ctx, | 107 | extern void *sha512_read_ctx (struct sha512_ctx const *restrict ctx, |
| 106 | void *restrict resbuf); | 108 | void *restrict resbuf); |
| 107 | extern void *sha384_read_ctx (const struct sha512_ctx *ctx, | 109 | extern void *sha384_read_ctx (struct sha512_ctx const *restrict ctx, |
| 108 | void *restrict resbuf); | 110 | void *restrict resbuf); |
| 109 | 111 | ||
| 110 | 112 | ||
| @@ -112,9 +114,9 @@ extern void *sha384_read_ctx (const struct sha512_ctx *ctx, | |||
| 112 | The result is always in little endian byte order, so that a byte-wise | 114 | The result is always in little endian byte order, so that a byte-wise |
| 113 | output yields to the wanted ASCII representation of the message | 115 | output yields to the wanted ASCII representation of the message |
| 114 | digest. */ | 116 | digest. */ |
| 115 | extern void *sha512_buffer (const char *buffer, size_t len, | 117 | extern void *sha512_buffer (char const *restrict buffer, size_t len, |
| 116 | void *restrict resblock); | 118 | void *restrict resblock); |
| 117 | extern void *sha384_buffer (const char *buffer, size_t len, | 119 | extern void *sha384_buffer (char const *restrict buffer, size_t len, |
| 118 | void *restrict resblock); | 120 | void *restrict resblock); |
| 119 | 121 | ||
| 120 | # endif | 122 | # endif |
| @@ -125,8 +127,8 @@ extern void *sha384_buffer (const char *buffer, size_t len, | |||
| 125 | The case that the last operation on STREAM was an 'ungetc' is not supported. | 127 | The case that the last operation on STREAM was an 'ungetc' is not supported. |
| 126 | The resulting message digest number will be written into the 64 (48) bytes | 128 | The resulting message digest number will be written into the 64 (48) bytes |
| 127 | beginning at RESBLOCK. */ | 129 | beginning at RESBLOCK. */ |
| 128 | extern int sha512_stream (FILE *stream, void *resblock); | 130 | extern int sha512_stream (FILE *restrict stream, void *restrict resblock); |
| 129 | extern int sha384_stream (FILE *stream, void *resblock); | 131 | extern int sha384_stream (FILE *restrict stream, void *restrict resblock); |
| 130 | 132 | ||
| 131 | 133 | ||
| 132 | # ifdef __cplusplus | 134 | # ifdef __cplusplus |
diff --git a/lib/string.c b/lib/string.c index c2e1b1f4184..b8f079aa78f 100644 --- a/lib/string.c +++ b/lib/string.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* streq and memeq functions. | 1 | /* streq, memeq, gl_strnul functions. |
| 2 | Copyright (C) 2025-2026 Free Software Foundation, Inc. | 2 | Copyright (C) 2025-2026 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is free software: you can redistribute it and/or modify | 4 | This file is free software: you can redistribute it and/or modify |
diff --git a/lib/string.in.h b/lib/string.in.h index 1b391507f49..599203c44db 100644 --- a/lib/string.in.h +++ b/lib/string.in.h | |||
| @@ -1230,6 +1230,58 @@ _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - " | |||
| 1230 | /* The following functions are not specified by POSIX. They are gnulib | 1230 | /* The following functions are not specified by POSIX. They are gnulib |
| 1231 | extensions. */ | 1231 | extensions. */ |
| 1232 | 1232 | ||
| 1233 | #if @GNULIB_STRNUL@ | ||
| 1234 | /* Returns a pointer to the terminating NUL byte of STRING. | ||
| 1235 | strnul (string) | ||
| 1236 | This is a type-generic macro: | ||
| 1237 | If STRING is a 'const char *', the result is 'const char *'. | ||
| 1238 | If STRING is a 'char *', the result is 'char *'. | ||
| 1239 | It is equivalent to | ||
| 1240 | string + strlen (string) | ||
| 1241 | or to | ||
| 1242 | strchr (string, '\0'). */ | ||
| 1243 | # ifdef __cplusplus | ||
| 1244 | extern "C" { | ||
| 1245 | # endif | ||
| 1246 | _GL_STRING_INLINE const char *gl_strnul (const char *string) | ||
| 1247 | _GL_ATTRIBUTE_PURE | ||
| 1248 | _GL_ARG_NONNULL ((1)); | ||
| 1249 | _GL_STRING_INLINE const char *gl_strnul (const char *string) | ||
| 1250 | { | ||
| 1251 | /* In gcc >= 7 or clang >= 4, we could use the expression | ||
| 1252 | strchr (string, '\0') | ||
| 1253 | because these compiler versions produce identical code for both | ||
| 1254 | expressions. But this optimization in not available in older | ||
| 1255 | compiler versions, and is also not available when the compiler | ||
| 1256 | option '-fno-builtin' is in use. */ | ||
| 1257 | return string + strlen (string); | ||
| 1258 | } | ||
| 1259 | # ifdef __cplusplus | ||
| 1260 | } | ||
| 1261 | # endif | ||
| 1262 | # ifdef __cplusplus | ||
| 1263 | template <typename T> T strnul (T); | ||
| 1264 | template <> inline const char *strnul<const char *> (const char *s) | ||
| 1265 | { return gl_strnul (s); } | ||
| 1266 | template <> inline char *strnul< char *> ( char *s) | ||
| 1267 | { return const_cast<char *>(gl_strnul (s)); } | ||
| 1268 | # else | ||
| 1269 | # if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __cplusplus) \ | ||
| 1270 | || (defined __clang__ && __clang_major__ >= 3) \ | ||
| 1271 | || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) \ | ||
| 1272 | || (__STDC_VERSION__ >= 201112L && !defined __GNUC__) | ||
| 1273 | /* The compiler supports _Generic from ISO C11. */ | ||
| 1274 | # define strnul(s) \ | ||
| 1275 | _Generic (s, \ | ||
| 1276 | char * : (char *) gl_strnul (s), \ | ||
| 1277 | const char * : gl_strnul (s)) | ||
| 1278 | # else | ||
| 1279 | # define strnul(s) \ | ||
| 1280 | ((char *) gl_strnul (s)) | ||
| 1281 | # endif | ||
| 1282 | # endif | ||
| 1283 | #endif | ||
| 1284 | |||
| 1233 | #if @GNULIB_STR_STARTSWITH@ | 1285 | #if @GNULIB_STR_STARTSWITH@ |
| 1234 | /* Returns true if STRING starts with PREFIX. | 1286 | /* Returns true if STRING starts with PREFIX. |
| 1235 | Returns false otherwise. */ | 1287 | Returns false otherwise. */ |