bl/strfuncs.c
author ali <ali@juiblex.co.uk>
Fri Jan 27 10:30:16 2012 +0000 (2012-01-27)
changeset 5 f600b0d1fc5d
parent 0 gclib/strfuncs.c@c2f4c0285180
permissions -rw-r--r--
Rename to bookloupe
     1 #include <stdlib.h>
     2 #include <string.h>
     3 #include <bl/mem.h>
     4 #include <bl/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 }