summaryrefslogtreecommitdiffstats
path: root/llvm/runtime/GCCLibraries/libc/string.c
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-19 21:44:41 +0000
committerChris Lattner <sabre@nondot.org>2004-02-19 21:44:41 +0000
commit74b387dea1e77d5429779de47977535b39e97584 (patch)
treed1d029d0982e6bcbf3c344931a97ca66d50dab3c /llvm/runtime/GCCLibraries/libc/string.c
parenta7350c53d2120ae584459fab611fb90a0cee7f52 (diff)
downloadbcm5719-llvm-74b387dea1e77d5429779de47977535b39e97584.tar.gz
bcm5719-llvm-74b387dea1e77d5429779de47977535b39e97584.zip
Add strndup
llvm-svn: 11638
Diffstat (limited to 'llvm/runtime/GCCLibraries/libc/string.c')
-rw-r--r--llvm/runtime/GCCLibraries/libc/string.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/runtime/GCCLibraries/libc/string.c b/llvm/runtime/GCCLibraries/libc/string.c
index 0ed4ced64c4..c13b11266cb 100644
--- a/llvm/runtime/GCCLibraries/libc/string.c
+++ b/llvm/runtime/GCCLibraries/libc/string.c
@@ -6,8 +6,6 @@
#include <stdlib.h>
#include <string.h>
-void *malloc(size_t);
-void free(void *);
size_t strlen(const char *Str) {
size_t Count = 0;
@@ -16,12 +14,21 @@ size_t strlen(const char *Str) {
}
char *strdup(const char *str) {
- long Len = strlen(str);
+ size_t Len = strlen(str);
char *Result = (char*)malloc((Len+1)*sizeof(char));
memcpy(Result, str, Len+1);
return Result;
}
+char *strndup(const char *str, size_t n) {
+ size_t Len = strlen(str);
+ if (Len > n) Len = n;
+ char *Result = (char*)malloc((Len+1)*sizeof(char));
+ memcpy(Result, str, Len);
+ Result[Len] = 0;
+ return Result;
+}
+
char *strcpy(char *s1, const char *s2) {
char *dest = s1;
while ((*s1++ = *s2++));
OpenPOWER on IntegriCloud