diff options
author | Florian Weimer <fweimer@redhat.com> | 2023-06-14 18:10:08 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2023-06-14 18:10:08 +0200 |
commit | 454a20c8756c9c1d55419153255fc7692b3d2199 (patch) | |
tree | a65ad84288a247995183089f4400e4fd080ecc9d /string/bits | |
parent | 7ba426a1115318fc11f4355f3161f35817a06ba4 (diff) | |
download | glibc-454a20c8756c9c1d55419153255fc7692b3d2199.tar.gz glibc-454a20c8756c9c1d55419153255fc7692b3d2199.tar.xz glibc-454a20c8756c9c1d55419153255fc7692b3d2199.zip |
Implement strlcpy and strlcat [BZ #178]
These functions are about to be added to POSIX, under Austin Group issue 986. The fortified strlcat implementation does not raise SIGABRT if the destination buffer does not contain a null terminator, it just inherits the non-failing regular strlcat behavior. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diffstat (limited to 'string/bits')
-rw-r--r-- | string/bits/string_fortified.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h index 9900df6104..23ef064168 100644 --- a/string/bits/string_fortified.h +++ b/string/bits/string_fortified.h @@ -139,4 +139,40 @@ __NTH (strncat (char *__restrict __dest, const char *__restrict __src, __glibc_objsize (__dest)); } +#ifdef __USE_MISC +extern size_t __strlcpy_chk (char *__dest, const char *__src, size_t __n, + size_t __destlen) __THROW; +extern size_t __REDIRECT_NTH (__strlcpy_alias, + (char *__dest, const char *__src, size_t __n), + strlcpy); + +__fortify_function size_t +__NTH (strlcpy (char *__restrict __dest, const char *__restrict __src, + size_t __n)) +{ + if (__glibc_objsize (__dest) != (size_t) -1 + && (!__builtin_constant_p (__n > __glibc_objsize (__dest)) + || __n > __glibc_objsize (__dest))) + return __strlcpy_chk (__dest, __src, __n, __glibc_objsize (__dest)); + return __strlcpy_alias (__dest, __src, __n); +} + +extern size_t __strlcat_chk (char *__dest, const char *__src, size_t __n, + size_t __destlen) __THROW; +extern size_t __REDIRECT_NTH (__strlcat_alias, + (char *__dest, const char *__src, size_t __n), + strlcat); + +__fortify_function size_t +__NTH (strlcat (char *__restrict __dest, const char *__restrict __src, + size_t __n)) +{ + if (__glibc_objsize (__dest) != (size_t) -1 + && (!__builtin_constant_p (__n > __glibc_objsize (__dest)) + || __n > __glibc_objsize (__dest))) + return __strlcat_chk (__dest, __src, __n, __glibc_objsize (__dest)); + return __strlcat_alias (__dest, __src, __n); +} +#endif /* __USE_MISC */ + #endif /* bits/string_fortified.h */ |