Qsmtp  0.30dev
Data Structures | Macros | Typedefs | Functions
sstring.h File Reference

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.

Data Structures

struct  string
 record of a string More...
 
struct  cstring
 record of a constant string More...
 

Macros

#define STREMPTY(x)   { (x).s = NULL; (x).len = 0; }
 

Typedefs

typedef struct string string
 
typedef struct cstring cstring
 

Functions

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...
 

Detailed Description

definition of string record and headers of corresponding helper functions

Function Documentation

static int dupstr ( string s,
const char *  t 
)
inlinestatic

duplicate a character string to a string buffer

Parameters
sthe string container
tthe character string
Returns
if the allocation was successful
Return values
0buffer was allocated
-1out 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
sthe string container
lenthe desired length of the embedded buffer
Returns
if the allocation was successful
Return values
0buffer was allocated
-1out of memory

If len is 0 s->s is set to NULL and 0 is returned.