Selaa lähdekoodia

move strndup back to string.c - used by strdup

tags/v0.9.3
Holger Lubitz 17 vuotta sitten
vanhempi
commit
bb94c143d9
1 muutettua tiedostoa jossa 15 lisäystä ja 0 poistoa
  1. 15
    0
      src/core/string.c

+ 15
- 0
src/core/string.c Näytä tiedosto

@@ -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…
Peruuta
Tallenna