src/pEp_string.h
author Volker Birk <vb@pep.foundation>
Mon, 15 Jan 2018 12:26:14 +0100
changeset 2378 b244047cdacc
parent 2377 008d02a90566
child 2440 3c45fce3ef40
permissions -rw-r--r--
adding documentation about C string.h compat
     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 //  caveat:
    24 //      one of the two parameters has to be set at least
    25 //
    26 //  calling with str and len is equivalent to strndup()
    27 //  calling with str but len=0 is equivalent to strdup()
    28 //  calling with str=NULL and len is equivalent to calloc()
    29 
    30 DYNAMIC_API char * new_string(const char *src, size_t len);
    31 
    32 
    33 // free_string() - free memory occupied by string
    34 //
    35 //  parameters:
    36 //      s (in)          pointer to string to free
    37 
    38 DYNAMIC_API void free_string(char *s);
    39 
    40 
    41 // string_dup() - duplicate a string
    42 //
    43 //  parameters:
    44 //      src (in)        string to duplicate
    45 //      len (in)        length of newly created string or 0 for default
    46 //
    47 //  return value:
    48 //      pointer to copy or NULL if out of memory
    49 
    50 DYNAMIC_API char * string_dup(const char *src, size_t len);
    51 
    52 
    53 #ifdef __cplusplus
    54 }
    55 #endif
    56