Browse Source

move strndup back to string.c - used by strdup

tags/v0.9.3
Holger Lubitz 17 years ago
parent
commit
bb94c143d9
1 changed files with 15 additions and 0 deletions
  1. 15
    0
      src/core/string.c

+ 15
- 0
src/core/string.c View File

@@ -333,6 +333,21 @@ void * memchr(const void *s, int c, size_t n)
333 333
 
334 334
 #endif
335 335
 
336
+char * strndup(const char *s, size_t n)
337
+{
338
+        size_t len = strlen(s);
339
+        char *new;
340
+
341
+        if (len>n)
342
+                len = n;
343
+        new = malloc(len+1);
344
+        if (new) {
345
+                new[len] = '\0';
346
+                memcpy(new,s,len);
347
+        }
348
+        return new;
349
+}
350
+
336 351
 char * strdup(const char *s) {
337 352
 	return strndup(s, ~((size_t)0));
338 353
 }

Loading…
Cancel
Save