definition of string record and headers of corresponding helper functions
More...
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
Go to the source code of this file.
|
#define | STREMPTY(x) { (x).s = NULL; (x).len = 0; } |
|
|
static int | newstr (string *s, const size_t len) |
| allocate a new string buffer of the given length More...
|
|
static int | dupstr (string *s, const char *t) |
| duplicate a character string to a string buffer More...
|
|
definition of string record and headers of corresponding helper functions
static int dupstr |
( |
string * |
s, |
|
|
const char * |
t |
|
) |
| |
|
inlinestatic |
duplicate a character string to a string buffer
- Parameters
-
s | the string container |
t | the character string |
- Returns
- if the allocation was successful
- Return values
-
0 | buffer was allocated |
-1 | out of memory |
The string container will receive a copy of the given string. The buffer will be allocated one byte longer and will be 0-terminated. The terminating 0-character will not be reflected by s->len.
If t has a length of 0 s->s is set to NULL and 0 is returned.
static int newstr |
( |
string * |
s, |
|
|
const size_t |
len |
|
) |
| |
|
inlinestatic |
allocate a new string buffer of the given length
- Parameters
-
s | the string container |
len | the desired length of the embedded buffer |
- Returns
- if the allocation was successful
- Return values
-
0 | buffer was allocated |
-1 | out of memory |
If len is 0 s->s is set to NULL and 0 is returned.