str.c revision b09be485e9373be4288f5615bbce6ebed65a425a
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2002-2003 Timo Sirainen */
c2cda8cd0043443566efc5da30f79865508a1947Timo Sirainenstring_t *str_new(pool_t pool, size_t initial_size)
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen return buffer_create_dynamic(pool, initial_size);
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen return str_new(pool_datastack_create(), initial_size);
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen /* remove the \0 - we don't want to keep it */
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainenconst unsigned char *str_data(const string_t *str)
b3fc5293379feb3640b23622bcc8f5f8d7f1e81dJosef 'Jeff' Sipek return buffer_get_modifiable_data(str, NULL);
204ee6ed414f5e4eeb6f6c10763b55daf56f11acJosef 'Jeff' Sipekvoid str_append(string_t *str, const char *cstr)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid str_append_n(string_t *str, const void *cstr, size_t max_len)
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen while (len < max_len && ((const char *)cstr)[len] != '\0')
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainenvoid str_append_c(string_t *str, unsigned char chr)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenvoid str_append_str(string_t *dest, const string_t *src)
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainenvoid str_printfa(string_t *str, const char *fmt, ...)
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainenvoid str_vprintfa(string_t *str, const char *fmt, va_list args)
5af5137f6dc0c9f358b7813e941e26f7bd735b3aTimo Sirainen /* the format string is modified only if %m exists in it. it happens
5af5137f6dc0c9f358b7813e941e26f7bd735b3aTimo Sirainen only in error conditions, so don't try to t_push() here since it'll
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen just slow down the normal code path. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen fmt = printf_format_fix_get_len(fmt, &init_size);
660ecbaf80e6b3cf3a70ed1e0cdf7f8af6d895d0Josef 'Jeff' Sipek init_size += SNPRINTF_INITIAL_EXTRA_SIZE;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* @UNSAFE */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen tmp = buffer_get_space_unsafe(str, pos, init_size);
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen /* didn't fit with the first guess. now we know the size,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen so try again. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen tmp = buffer_get_space_unsafe(str, pos, ret + 1);
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen /* drop the unused data, including terminating NUL */
71aed7ba87b5fd5e96e97a22d89ac025b883d60aTimo Sirainenvoid str_insert(string_t *str, size_t pos, const char *cstr)