[llvm-commits] [parallel] CVS: llvm/runtime/GCCLibraries/libc/string.c

Misha Brukman brukman at cs.uiuc.edu
Mon Mar 1 18:01:37 PST 2004


Changes in directory llvm/runtime/GCCLibraries/libc:

string.c updated: 1.6 -> 1.6.6.1

---
Log message:

Merge from trunk

---
Diffs of the changes:  (+16 -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.6.6.1
--- llvm/runtime/GCCLibraries/libc/string.c:1.6	Tue Oct 21 12:53:16 2003
+++ llvm/runtime/GCCLibraries/libc/string.c	Mon Mar  1 17:58:45 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,15 +14,30 @@
 }
 
 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++));
+  return dest;
+}
+
+char *strncpy(char *s1, const char *s2, size_t n) {
+  char *dest = s1;
+  while (n-- && (*s1++ = *s2++));
   return dest;
 }
 





More information about the llvm-commits mailing list