src/pEp_string.c
author Volker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 17:10:23 +0200
branchsync
changeset 2899 63b619aef131
parent 2462 48b526a0daac
child 4792 7056435ab9e7
permissions -rw-r--r--
somewhat bigger
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include "platform.h"
     5 #include "pEp_string.h"
     6 
     7 #include <stdlib.h>
     8 #include <assert.h>
     9 
    10 DYNAMIC_API char * new_string(const char *src, size_t len)
    11 {
    12     char *s = NULL;
    13     if (src) {
    14         if (len)
    15             s = strndup(src, len);
    16         else
    17             s = strdup(src);
    18         assert(s);
    19     }
    20     else {
    21         s = calloc(1, len + 1);
    22         assert(s);
    23     }
    24 
    25     return s;
    26 }
    27 
    28 
    29 DYNAMIC_API void free_string(char *s)
    30 {
    31     free(s);
    32 }
    33 
    34 DYNAMIC_API char * string_dup(const char *src, size_t len)
    35 {
    36     assert(src);
    37     if (!src)
    38         return NULL;
    39 
    40     char *s = NULL;
    41     if (len)
    42         s = strndup(src, len);
    43     else
    44         s = strdup(src);
    45     assert(s);
    46 
    47     return s;
    48 }
    49