From 5be23dd97e360d19c8abb4c0c534f5d5f9d3691a Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 19 Dec 2022 07:01:24 -0700 Subject: Inline strlcat(), strlcpy() These short functions are reasonably frequently used. --- util.c | 74 ------------------------------------------------------------------ 1 file changed, 74 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 8da7c11fa7..16c87e280e 100644 --- a/util.c +++ b/util.c @@ -5738,80 +5738,6 @@ S_xs_version_bootcheck(pTHX_ U32 items, U32 ax, const char *xs_p, } } -/* -=for apidoc my_strlcat - -The C library C if available, or a Perl implementation of it. -This operates on C C-terminated strings. - -C appends string C to the end of C. It will append at -most S> characters. It will then C-terminate, -unless C is 0 or the original C string was longer than C (in -practice this should not happen as it means that either C is incorrect or -that C is not a proper C-terminated string). - -Note that C is the full size of the destination buffer and -the result is guaranteed to be C-terminated if there is room. Note that -room for the C should be included in C. - -The return value is the total length that C would have if C is -sufficiently large. Thus it is the initial length of C plus the length of -C. If C is smaller than the return, the excess was not appended. - -=cut - -Description stolen from http://man.openbsd.org/strlcat.3 -*/ -#ifndef HAS_STRLCAT -Size_t -Perl_my_strlcat(char *dst, const char *src, Size_t size) -{ - Size_t used, length, copy; - - used = strlen(dst); - length = strlen(src); - if (size > 0 && used < size - 1) { - copy = (length >= size - used) ? size - used - 1 : length; - memcpy(dst + used, src, copy); - dst[used + copy] = '\0'; - } - return used + length; -} -#endif - - -/* -=for apidoc my_strlcpy - -The C library C if available, or a Perl implementation of it. -This operates on C C-terminated strings. - -C copies up to S> characters from the string C -to C, C-terminating the result if C is not 0. - -The return value is the total length C would be if the copy completely -succeeded. If it is larger than C, the excess was not copied. - -=cut - -Description stolen from http://man.openbsd.org/strlcpy.3 -*/ -#ifndef HAS_STRLCPY -Size_t -Perl_my_strlcpy(char *dst, const char *src, Size_t size) -{ - Size_t length, copy; - - length = strlen(src); - if (size > 0) { - copy = (length >= size) ? size - 1 : length; - memcpy(dst, src, copy); - dst[copy] = '\0'; - } - return length; -} -#endif - PERL_STATIC_INLINE bool S_gv_has_usable_name(pTHX_ GV *gv) { -- cgit v1.2.1