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
vb@2376
     1
// This file is under GNU General Public License 3.0
vb@2376
     2
// see LICENSE.txt
vb@2376
     3
vb@2376
     4
#pragma once
vb@2376
     5
vb@2376
     6
#include <string.h>
vb@2376
     7
#include "dynamic_api.h"
vb@2376
     8
vb@2376
     9
#ifdef __cplusplus
vb@2376
    10
extern "C" {
vb@2376
    11
#endif
vb@2376
    12
vb@2376
    13
vb@2376
    14
// new_string() - allocate a new string
vb@2376
    15
//
vb@2376
    16
//  parameters:
vb@2376
    17
//      src (in)        string to copy or NULL
vb@2376
    18
//      len (in)        length of newly created string or 0 for default
vb@2376
    19
//
vb@2376
    20
//  return value:
vb@2376
    21
//      pointer to string object or NULL if out of memory
vb@2376
    22
//
vb@2376
    23
//  caveat:
vb@2376
    24
//      one of the two parameters has to be set at least
vb@2378
    25
//
vb@2378
    26
//  calling with str and len is equivalent to strndup()
vb@2378
    27
//  calling with str but len=0 is equivalent to strdup()
vb@2378
    28
//  calling with str=NULL and len is equivalent to calloc()
vb@2376
    29
vb@2376
    30
DYNAMIC_API char * new_string(const char *src, size_t len);
vb@2376
    31
vb@2376
    32
vb@2376
    33
// free_string() - free memory occupied by string
vb@2376
    34
//
vb@2376
    35
//  parameters:
vb@2377
    36
//      s (in)          pointer to string to free
vb@2376
    37
vb@2376
    38
DYNAMIC_API void free_string(char *s);
vb@2376
    39
vb@2376
    40
vb@2376
    41
// string_dup() - duplicate a string
vb@2376
    42
//
vb@2376
    43
//  parameters:
vb@2376
    44
//      src (in)        string to duplicate
vb@2376
    45
//      len (in)        length of newly created string or 0 for default
vb@2376
    46
//
vb@2376
    47
//  return value:
vb@2376
    48
//      pointer to copy or NULL if out of memory
vb@2376
    49
vb@2376
    50
DYNAMIC_API char * string_dup(const char *src, size_t len);
vb@2376
    51
vb@2376
    52
vb@2376
    53
#ifdef __cplusplus
vb@2376
    54
}
vb@2376
    55
#endif
vb@2376
    56