src/pEp_string.h
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 22 Dec 2020 17:48:03 +0100
branchRelease_2.1
changeset 5246 67016f508d40
parent 2440 3c45fce3ef40
child 5248 217b4067d60b
permissions -rw-r--r--
ENGINE-870 graft: replace #pragma once with include guards
vb@2376
     1
// This file is under GNU General Public License 3.0
vb@2376
     2
// see LICENSE.txt
vb@2376
     3
krista@5246
     4
#ifndef PeP_STRING_H
krista@5246
     5
#define PeP_STRING_H
vb@2376
     6
vb@2376
     7
#include <string.h>
vb@2376
     8
#include "dynamic_api.h"
vb@2376
     9
vb@2376
    10
#ifdef __cplusplus
vb@2376
    11
extern "C" {
vb@2376
    12
#endif
vb@2376
    13
vb@2376
    14
vb@2376
    15
// new_string() - allocate a new string
vb@2376
    16
//
vb@2376
    17
//  parameters:
vb@2376
    18
//      src (in)        string to copy or NULL
vb@2376
    19
//      len (in)        length of newly created string or 0 for default
vb@2376
    20
//
vb@2376
    21
//  return value:
vb@2376
    22
//      pointer to string object or NULL if out of memory
vb@2376
    23
//
vb@2378
    24
//  calling with str and len is equivalent to strndup()
vb@2378
    25
//  calling with str but len=0 is equivalent to strdup()
vb@2440
    26
//  calling with str=NULL is equivalent to calloc()
vb@2376
    27
vb@2376
    28
DYNAMIC_API char * new_string(const char *src, size_t len);
vb@2376
    29
vb@2376
    30
vb@2376
    31
// free_string() - free memory occupied by string
vb@2376
    32
//
vb@2376
    33
//  parameters:
vb@2377
    34
//      s (in)          pointer to string to free
vb@2376
    35
vb@2376
    36
DYNAMIC_API void free_string(char *s);
vb@2376
    37
vb@2376
    38
vb@2376
    39
// string_dup() - duplicate a string
vb@2376
    40
//
vb@2376
    41
//  parameters:
vb@2376
    42
//      src (in)        string to duplicate
vb@2376
    43
//      len (in)        length of newly created string or 0 for default
vb@2376
    44
//
vb@2376
    45
//  return value:
vb@2376
    46
//      pointer to copy or NULL if out of memory
vb@2376
    47
vb@2376
    48
DYNAMIC_API char * string_dup(const char *src, size_t len);
vb@2376
    49
vb@2376
    50
vb@2376
    51
#ifdef __cplusplus
vb@2376
    52
}
vb@2376
    53
#endif
vb@2376
    54
krista@5246
    55
#endif