FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Functions | Variables
Dynamic string functions

Handle dynamic string. More...

Collaboration diagram for Dynamic string functions:

Macros

#define DSTR_INITIALIZER   ((struct tds_dstr*) &tds_str_empty)
 Initializer, used to initialize string like in the following example. More...
 
#define tds_dstr_empty(s)   tds_dstr_free(s)
 Make a string empty.
 

Functions

DSTRtds_dstr_alloc (DSTR *s, size_t length)
 allocate space for length char More...
 
static char * tds_dstr_buf (DSTR *s)
 Returns a buffer to edit the string. More...
 
DSTRtds_dstr_copy (DSTR *s, const char *src)
 copy a string from another More...
 
DSTRtds_dstr_copyn (DSTR *s, const char *src, size_t length)
 Set string to a given buffer of characters. More...
 
static const char * tds_dstr_cstr (DSTR *s)
 Returns a C version (NUL terminated string) of dstr.
 
DSTRtds_dstr_dup (DSTR *s, const DSTR *src)
 Duplicate a string from another dynamic string. More...
 
void tds_dstr_free (DSTR *s)
 free string
 
static void tds_dstr_init (DSTR *s)
 init a string with empty
 
static int tds_dstr_isempty (DSTR *s)
 test if string is empty
 
static size_t tds_dstr_len (DSTR *s)
 Returns the length of the string in bytes.
 
DSTRtds_dstr_set (DSTR *s, char *src)
 set a string from another buffer. More...
 
DSTRtds_dstr_setlen (DSTR *s, size_t length)
 limit length of string, MUST be <= current length More...
 
void tds_dstr_zero (DSTR *s)
 clear all string filling with zeroes (mainly for security reason)
 

Variables

const struct tds_dstr tds_str_empty
 Internal representation for an empty string.
 

Detailed Description

Handle dynamic string.

In this string are always valid (you don't have NULL pointer, only empty strings)

Macro Definition Documentation

#define DSTR_INITIALIZER   ((struct tds_dstr*) &tds_str_empty)

Initializer, used to initialize string like in the following example.

1 DSTR s = DSTR_INITIALIZER;

Function Documentation

DSTR * tds_dstr_alloc ( DSTR s,
size_t  length 
)

allocate space for length char

Parameters
sdynamic string
lengthnew length
Returns
string allocated or NULL on memory error

Here is the caller graph for this function:

static char* tds_dstr_buf ( DSTR s)
inlinestatic

Returns a buffer to edit the string.

Be careful to avoid buffer overflows and remember to set the correct length at the end of the editing if changed.

Here is the caller graph for this function:

DSTR * tds_dstr_copy ( DSTR s,
const char *  src 
)

copy a string from another

Parameters
sdynamic string
srcsource buffer
Returns
string copied or NULL on memory error

Here is the call graph for this function:

Here is the caller graph for this function:

DSTR * tds_dstr_copyn ( DSTR s,
const char *  src,
size_t  length 
)

Set string to a given buffer of characters.

Parameters
sdynamic string
srcsource buffer
lengthlength of source buffer
Returns
string copied or NULL on memory error

Here is the caller graph for this function:

DSTR * tds_dstr_dup ( DSTR s,
const DSTR src 
)

Duplicate a string from another dynamic string.

Parameters
soutput string
srcsource string to copy
Returns
string copied or NULL on memory error

Here is the call graph for this function:

Here is the caller graph for this function:

DSTR * tds_dstr_set ( DSTR s,
char *  src 
)

set a string from another buffer.

The string will use the supplied buffer (it not copy the string), so it should be a pointer returned by malloc.

Parameters
sdynamic string
srcsource buffer
Returns
string copied or NULL on memory error

Here is the call graph for this function:

DSTR * tds_dstr_setlen ( DSTR s,
size_t  length 
)

limit length of string, MUST be <= current length

Parameters
sdynamic string
lengthnew length

Here is the caller graph for this function: