src/pEp_string.h
author Volker Birk <vb@pep.foundation>
Wed, 24 Jan 2018 11:11:20 +0100
changeset 2440 3c45fce3ef40
parent 2378 b244047cdacc
child 4792 7056435ab9e7
permissions -rw-r--r--
allowing creation of zero length strings
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #pragma once
     5 
     6 #include <string.h>
     7 #include "dynamic_api.h"
     8 
     9 #ifdef __cplusplus
    10 extern "C" {
    11 #endif
    12 
    13 
    14 // new_string() - allocate a new string
    15 //
    16 //  parameters:
    17 //      src (in)        string to copy or NULL
    18 //      len (in)        length of newly created string or 0 for default
    19 //
    20 //  return value:
    21 //      pointer to string object or NULL if out of memory
    22 //
    23 //  calling with str and len is equivalent to strndup()
    24 //  calling with str but len=0 is equivalent to strdup()
    25 //  calling with str=NULL is equivalent to calloc()
    26 
    27 DYNAMIC_API char * new_string(const char *src, size_t len);
    28 
    29 
    30 // free_string() - free memory occupied by string
    31 //
    32 //  parameters:
    33 //      s (in)          pointer to string to free
    34 
    35 DYNAMIC_API void free_string(char *s);
    36 
    37 
    38 // string_dup() - duplicate a string
    39 //
    40 //  parameters:
    41 //      src (in)        string to duplicate
    42 //      len (in)        length of newly created string or 0 for default
    43 //
    44 //  return value:
    45 //      pointer to copy or NULL if out of memory
    46 
    47 DYNAMIC_API char * string_dup(const char *src, size_t len);
    48 
    49 
    50 #ifdef __cplusplus
    51 }
    52 #endif
    53