Automatically allocated strings.
Used instead of statically-allocated strings as read-only buffers
(after allocation, string should be freed and allocated again)
Auto-allocated strings may be mutable, but you should ensure that
they were not constructed from aas_set() call. In that case behavior
is undefined.
Since arguments passed to AAS may be mutable (but should not be),
it uses "n" functions to protect from possible buffer overflow.
Constants
AAS_ALLOCATION_ERROR, AAS_BUF_NOT_EMPTY, AAS_INVALID_ARGUMENT
AAS errors
VALUES
-
AAS_BUF_NOT_EMPTY - string was already allocated
-
AAS_ALLOCATION_ERROR - failed to allocate new buffer
-
AAS_INVALID_ARGUMENT - one of required argument is invalid (probably NULL)
#define AAS_BUF_NOT_EMPTY ((size_t) -1) #define AAS_ALLOCATION_ERROR ((size_t) -2) #define AAS_INVALID_ARGUMENT ((size_t) -3)
Functions
AAS_IS_OK
Checks if error was occured in aas function
#define AAS_IS_OK(ret)
aas_allocate
public
Allocate new auto-allocated string.
Use only with pair of aas_free
ARGUMENTS
-
count - number of characters without null-terminator
RETURN VALUES
NULL or pointer to allocated buffer
LIBEXPORT char* aas_allocate(size_t count)
aas_vprintf
public
Formatted print for auto-allocated strings
ARGUMENTS
-
aas - pointer to auto-allocated string
-
format - printf's format string
RETURN VALUES
number of printed characters or AAS error
LIBEXPORT size_t aas_vprintf(char** aas, const char* format, va_list va)
aas_printf
public
STATIC_INLINE size_t aas_printf(char** aas, const char* format, ...) STATIC_INLINE size_t aas_printf(char** aas, const char* format, ...)
aas_merge
public
Merge several strings into one and allocate it
ARGUMENTS
-
aas - pointer to auto-allocated string
-
str - first piece of strings
RETURN VALUES
number of printed characters or AAS error
NOTES
last string should be set to NULL
LIBEXPORT size_t aas_merge(char** aas, const char* str, ...)
aas_copy_n
public
Copy up to count characters
ARGUMENTS
-
aas - pointer to auto-allocated string
-
str - source string
RETURN VALUES
number of copied characters or AAS error
LIBEXPORT size_t aas_copy_n(char** aas, const char* str, size_t count)
aas_copy
public
Copy string to auto-allocated string
ARGUMENTS
-
aas - pointer to auto-allocated string
-
str - source string
RETURN VALUES
number of copied characters or AAS error
LIBEXPORT size_t aas_copy(char** aas, const char* str)
aas_set_impl
public
LIBEXPORT void aas_set_impl(char** aas, const char* str)
AAS_CONST_STR, aas_set
Set auto-allocated string to compile-time constant value
ARGUMENTS
-
aas - pointer to auto-allocated string
-
str - constant string literal
#define AAS_CONST_STR(str) #define aas_set(aas, str)
aas_free
public
Frees auto-allocated string (if it was dynamically allocated)
LIBEXPORT void aas_free(char** aas)
aas_init
public
static char** aas_init(char** aas)