diff options
author | Steve Peters <steve@fisharerojo.org> | 2006-07-10 11:28:24 +0000 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2006-07-10 11:28:24 +0000 |
commit | a6cc41194dbe50598d9f33497d88c8589cd7a8c0 (patch) | |
tree | b2660dbedb85b00f89e7a2f39dc13d7dea631713 | |
parent | eeb9de022215ff745a61968bf9408965f4687655 (diff) | |
download | perl-a6cc41194dbe50598d9f33497d88c8589cd7a8c0.tar.gz |
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
-rw-r--r-- | embed.fnc | 8 | ||||
-rw-r--r-- | embed.h | 8 | ||||
-rw-r--r-- | global.sym | 2 | ||||
-rw-r--r-- | perl.h | 12 | ||||
-rw-r--r-- | proto.h | 8 | ||||
-rw-r--r-- | util.c | 33 |
6 files changed, 71 insertions, 0 deletions
@@ -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) @@ -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 c737e97170..4d2cb51753 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: @@ -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 <hom00@utsglobal.com> */ #ifdef UTS @@ -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); @@ -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 |