From: Steve Peters Date: Mon, 10 Jul 2006 11:28:24 +0000 (+0000) Subject: Add Russ Allbery's public domain implementations of strlcat and X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6cc41194dbe50598d9f33497d88c8589cd7a8c0;p=p5sagit%2Fp5-mst-13.2.git Add Russ Allbery's public domain implementations of strlcat and strlcpy as Perl_my_strlcat and Perl_my_strlcpy to the Perl core. Thanks Russ! p4raw-id: //depot/perl@28525 --- diff --git a/embed.fnc b/embed.fnc index 81127e0..bfd7dce 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1718,6 +1718,14 @@ px |void |my_clearenv Apo |void* |my_cxt_init |NN int *index|size_t size #endif +#ifndef HAS_STRLCAT +Apno |Size_t |my_strlcat |NULLOK char *dst|NULLOK const char *src|Size_t size +#endif + +#ifndef HAS_STRLCPY +Apno |Size_t |my_strlcpy |NULLOK char *dst|NULLOK const char *src|Size_t size +#endif + #ifdef PERL_MAD Mnp |void |pad_peg |NN const char* s #if defined(PERL_IN_DUMP_C) || defined(PERL_DECL_PROT) diff --git a/embed.h b/embed.h index 8e26433..3c4c65c 100644 --- a/embed.h +++ b/embed.h @@ -1773,6 +1773,10 @@ #endif #ifdef PERL_IMPLICIT_CONTEXT #endif +#ifndef HAS_STRLCAT +#endif +#ifndef HAS_STRLCPY +#endif #ifdef PERL_MAD #ifdef PERL_CORE #define pad_peg Perl_pad_peg @@ -3966,6 +3970,10 @@ #endif #ifdef PERL_IMPLICIT_CONTEXT #endif +#ifndef HAS_STRLCAT +#endif +#ifndef HAS_STRLCPY +#endif #ifdef PERL_MAD #ifdef PERL_CORE #define pad_peg Perl_pad_peg diff --git a/global.sym b/global.sym index c737e97..4d2cb51 100644 --- a/global.sym +++ b/global.sym @@ -721,4 +721,6 @@ Perl_my_sprintf Perl_my_snprintf Perl_my_vsnprintf Perl_my_cxt_init +Perl_my_strlcat +Perl_my_strlcpy # ex: set ro: diff --git a/perl.h b/perl.h index 8fd8e21..9c32f96 100644 --- a/perl.h +++ b/perl.h @@ -1488,6 +1488,18 @@ int sockatmark(int); # define PERL_MY_VSNPRINTF_GUARDED #endif +#ifdef HAS_STRLCAT +# define my_strlcat strlcat +#else +# define my_strlcat Perl_my_strlcat +#endif + +#ifdef HAS_STRLCPY +# define my_strlcpy strlcpy +#else +# define my_strlcpy Perl_my_strlcpy +#endif + /* Configure gets this right but the UTS compiler gets it wrong. -- Hal Morris */ #ifdef UTS diff --git a/proto.h b/proto.h index c595c31..928ba5e 100644 --- a/proto.h +++ b/proto.h @@ -4407,6 +4407,14 @@ PERL_CALLCONV void* Perl_my_cxt_init(pTHX_ int *index, size_t size) #endif +#ifndef HAS_STRLCAT +PERL_CALLCONV Size_t Perl_my_strlcat(char *dst, const char *src, Size_t size); +#endif + +#ifndef HAS_STRLCPY +PERL_CALLCONV Size_t Perl_my_strlcpy(char *dst, const char *src, Size_t size); +#endif + #ifdef PERL_MAD PERL_CALLCONV void Perl_pad_peg(const char* s) __attribute__nonnull__(1); diff --git a/util.c b/util.c index cecec9c..6e291d3 100644 --- a/util.c +++ b/util.c @@ -5530,6 +5530,39 @@ Perl_my_cxt_init(pTHX_ int *index, size_t size) } #endif +#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 + +#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 + /* * Local variables: * c-indentation-style: bsd