gclib/strfuncs.c
author ali <ali@juiblex.co.uk>
Fri Jan 27 00:28:11 2012 +0000 (2012-01-27)
changeset 4 218904410231
permissions -rw-r--r--
Add workaround for missing -framework Carbon
     1 #include <stdlib.h>
     2 #include <string.h>
     3 #include <gclib/mem.h>
     4 #include <gclib/strfuncs.h>
     5 
     6 /*
     7  * Like strndup, but only returns NULL if str is NULL.
     8  * Note that this routine copies n bytes rather than n characters.
     9  */
    10 char *str_ndup(const char *str,size_t n)
    11 {
    12     char *dup;
    13     if (!str)
    14 	return NULL;
    15     dup=mem_alloc0(n+1,1);
    16     strncpy(dup,str,n);
    17     return dup;
    18 }
    19 
    20 /*
    21  * Like strdup, but only returns NULL if str is NULL.
    22  */
    23 char *str_dup(const char *str)
    24 {
    25     return str_ndup(str,strlen(str));
    26 }