aboutsummaryrefslogtreecommitdiffstats
path: root/libntp/strdup.c
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2020-06-24 00:20:45 +0000
committerCy Schubert <cy@FreeBSD.org>2020-06-24 00:20:45 +0000
commit3914721463f70500ecc1f59312b122d8788465cf (patch)
treef253e72838d762e229ca71912a4a928e96cac2bd /libntp/strdup.c
parent5171bc9b11192d9ad273db7854787eaa65eb9997 (diff)
downloadsrc-vendor/ntp.tar.gz
src-vendor/ntp.zip
Import ntp-4.2.8p15.vendor/ntp/4.2.8p15vendor/ntp
Security: ntp bug 3661
Notes
Notes: svn path=/vendor/ntp/dist/; revision=362565 svn path=/vendor/ntp/4.2.8p15/; revision=362566; tag=vendor/ntp/4.2.8p15
Diffstat (limited to 'libntp/strdup.c')
-rw-r--r--libntp/strdup.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/libntp/strdup.c b/libntp/strdup.c
index 62d5a16d433c..8af9ff81b39c 100644
--- a/libntp/strdup.c
+++ b/libntp/strdup.c
@@ -1,13 +1,15 @@
#include <config.h>
#include <ntp_assert.h>
-#include "ntp_malloc.h"
#include <string.h>
+#include "ntp_malloc.h"
+#include "l_stdlib.h"
-#ifndef HAVE_STRDUP
+#define STRDUP_EMPTY_UNIT
+#ifndef HAVE_STRDUP
+# undef STRDUP_EMPTY_UNIT
char *strdup(const char *s);
-
char *
strdup(
const char *s
@@ -24,6 +26,30 @@ strdup(
return cp;
}
-#else
+#endif
+
+#ifndef HAVE_MEMCHR
+# undef STRDUP_EMPTY_UNIT
+void *memchr(const void *s, int c, size_t n)
+{
+ const unsigned char *p = s;
+ while (n && *p != c) {
+ --n;
+ ++p;
+ }
+ return n ? (char*)p : NULL;
+}
+#endif
+
+#ifndef HAVE_STRNLEN
+# undef STRDUP_EMPTY_UNIT
+size_t strnlen(const char *s, size_t n)
+{
+ const char *e = memchr(s, 0, n);
+ return e ? (size_t)(e - s) : n;
+}
+#endif
+
+#ifdef STRDUP_EMPTY_UNIT
int strdup_c_nonempty_compilation_unit;
#endif