Wed Oct 28 11:46:47 2009

Asterisk developer's documentation


ast_str Struct Reference

The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field to indicate the type of storage. Three special constants indicate malloc, alloca() or static variables, all other values indicate a struct ast_threadstorage pointer. More...

#include <strings.h>

Collaboration diagram for ast_str:

Collaboration graph
[legend]

Data Fields

size_t len
char str [0]
struct ast_threadstoragets
size_t used

Detailed Description

The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field to indicate the type of storage. Three special constants indicate malloc, alloca() or static variables, all other values indicate a struct ast_threadstorage pointer.

Support for dynamic strings.

A dynamic string is just a C string prefixed by a few control fields that help setting/appending/extending it using a printf-like syntax.

One should never declare a variable with this type, but only a pointer to it, e.g.

struct ast_str *ds;

The pointer can be initialized with the following:

ds = ast_str_create(init_len); creates a malloc()'ed dynamic string;

ds = ast_str_alloca(init_len); creates a string on the stack (not very dynamic!).

ds = ast_str_thread_get(ts, init_len) creates a malloc()'ed dynamic string associated to the thread-local storage key ts

Finally, the string can be manipulated with the following:

ast_str_set(&buf, max_len, fmt, ...) ast_str_append(&buf, max_len, fmt, ...)

and their varargs variant

ast_str_set_va(&buf, max_len, ap) ast_str_append_va(&buf, max_len, ap)

Returns:
All the functions return <0 in case of error, or the length of the string added to the buffer otherwise.

Definition at line 344 of file strings.h.


Field Documentation

size_t len

The current maximum length of the string

Definition at line 345 of file strings.h.

Referenced by add_sdp(), ast_str_thread_get(), handle_dbget(), load_config(), pbx_find_extension(), and pgsql_reconnect().

char str[0]

struct ast_threadstorage* ts [read]

What kind of storage is this ?

Definition at line 347 of file strings.h.

Referenced by ast_str_thread_get().

size_t used


The documentation for this struct was generated from the following file:

Generated on Wed Oct 28 11:46:47 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6