FreeTDS API
Classes | Macros | Typedefs | Functions | Variables
Dynamic string functions

Handle dynamic string. More...

Collaboration diagram for Dynamic string functions:

Classes

struct  tds_dstr
 Structure to hold a string. More...
 

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.
 

Typedefs

typedef struct tds_dstrDSTR
 Structure to hold a string. More...
 

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 (const 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 (const DSTR *s)
 test if string is empty
 
static size_t tds_dstr_len (const 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

◆ DSTR_INITIALIZER

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

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

Typedef Documentation

◆ DSTR

typedef struct tds_dstr * DSTR

Structure to hold a string.

Use tds_dstr_* functions/macros, do not access members directly. There should be always a buffer.

Function Documentation

◆ tds_dstr_alloc()

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

◆ tds_dstr_buf()

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.

◆ tds_dstr_copy()

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:

◆ tds_dstr_copyn()

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:

◆ tds_dstr_dup()

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:

◆ tds_dstr_set()

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:

◆ tds_dstr_setlen()

DSTR * tds_dstr_setlen ( DSTR s,
size_t  length 
)

limit length of string, MUST be <= current length

Parameters
sdynamic string
lengthnew length