[llvm-commits] CVS: llvm/runtime/GCCLibraries/libc/string.c
Chris Lattner
lattner at cs.uiuc.edu
Thu Feb 19 15:45:01 PST 2004
Changes in directory llvm/runtime/GCCLibraries/libc:
string.c updated: 1.6 -> 1.7
---
Log message:
Add strndup
---
Diffs of the changes: (+10 -3)
Index: llvm/runtime/GCCLibraries/libc/string.c
diff -u llvm/runtime/GCCLibraries/libc/string.c:1.6 llvm/runtime/GCCLibraries/libc/string.c:1.7
--- llvm/runtime/GCCLibraries/libc/string.c:1.6 Tue Oct 21 12:53:16 2003
+++ llvm/runtime/GCCLibraries/libc/string.c Thu Feb 19 15:44:41 2004
@@ -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,9 +14,18 @@
}
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;
}
More information about the llvm-commits
mailing list