summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/port/gen/strndup.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/usr/src/lib/libc/port/gen/strndup.c b/usr/src/lib/libc/port/gen/strndup.c
index a31f60827c..01e6b83a53 100644
--- a/usr/src/lib/libc/port/gen/strndup.c
+++ b/usr/src/lib/libc/port/gen/strndup.c
@@ -21,10 +21,12 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2018 Joyent, Inc.
*/
#include "lint.h"
#include <string.h>
+#include <strings.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -38,7 +40,10 @@ strndup(const char *s1, size_t n)
char *s2;
n = strnlen(s1, n);
- if ((s2 = malloc(n + 1)) != NULL)
- (void) strlcpy(s2, s1, n + 1);
+ if ((s2 = malloc(n + 1)) != NULL) {
+ bcopy(s1, s2, n);
+ s2[n] = '\0';
+ }
+
return (s2);
}