Dynamic string functions
LibTDS API

Handle dynamic string. In this string are always valid (you don't have NULL pointer, only empty strings) 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_dstr * | DSTR
| Structure to hold a string. More...

## Functions

DSTR * | tds_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...
DSTR * | tds_dstr_copy (DSTR *s, const char *src)
| copy a string from another More...
DSTR * | tds_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.
DSTR * | tds_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.
DSTR * | tds_dstr_set (DSTR *s, char *src)
| set a string from another buffer. More...
DSTR * | tds_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.

DSTR s = DSTR_INITIALIZER;

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

  s | dynamic string
  length | new length

Returns
  string allocated or NULL on memory error

## tds_dstr_buf()

static char* tds_dstr_buf | ( | DSTR * | s | ) |

inline static

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

  s | dynamic string
  src | source 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

  s | dynamic string
  src | source buffer
  length | length 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

  s | output string
  src | source 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

  s | dynamic string
  src | source 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

  s | dynamic string
  length | new length

tds_dstr
Structure to hold a string.
Definition: string.h:36
DSTR_INITIALIZER
#define DSTR_INITIALIZER
Initializer, used to initialize string like in the following example.
Definition: string.h:49