summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Peters <steve@fisharerojo.org>2006-07-10 11:28:24 +0000
committerSteve Peters <steve@fisharerojo.org>2006-07-10 11:28:24 +0000
commita6cc41194dbe50598d9f33497d88c8589cd7a8c0 (patch)
treeb2660dbedb85b00f89e7a2f39dc13d7dea631713
parenteeb9de022215ff745a61968bf9408965f4687655 (diff)
downloadperl-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.fnc8
-rw-r--r--embed.h8
-rw-r--r--global.sym2
-rw-r--r--perl.h12
-rw-r--r--proto.h8
-rw-r--r--util.c33
6 files changed, 71 insertions, 0 deletions
diff --git a/embed.fnc b/embed.fnc
index 81127e0375..bfd7dcebfe 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 8e26433190..3c4c65c377 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 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:
diff --git a/perl.h b/perl.h
index 8fd8e21ebc..9c32f969c4 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 <hom00@utsglobal.com> */
#ifdef UTS
diff --git a/proto.h b/proto.h
index c595c31b36..928ba5ead8 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 cecec9c878..6e291d310f 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