2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
11 #include <sys/types.h>
12 #include <stdlib.h> /* malloc(), free() */
14 #include <string.h> /* str...() */
16 #include <stdarg.h> /* varargs in sprintf/appendf */
19 #include "ecore_private.h"
21 #include "Ecore_Config.h"
22 #include "ecore_config_util.h"
24 #include "ecore_config_private.h"
28 /*****************************************************************************/
35 estring *e = malloc(sizeof(estring));
39 memset(e, 0, sizeof(estring));
40 if ((size > 0) && (e->str = malloc(size)))
47 estring_disown(estring * e)
60 estring_appendf(estring * e, const char *fmt, ...)
67 return ECORE_CONFIG_ERR_FAIL;
71 e->used = e->alloc = 0;
72 if (!(e->str = (char *)malloc(e->alloc = CHUNKLEN)))
73 return ECORE_CONFIG_ERR_OOM;
77 need = vsnprintf(NULL, 0, fmt, ap);
80 if (need >= (e->alloc - e->used))
82 e->alloc = e->used + need + (CHUNKLEN - (need % CHUNKLEN));
84 if (!(p = (char *)realloc(e->str, e->alloc)))
87 e->alloc = e->used = 0;
88 return ECORE_CONFIG_ERR_OOM;
94 need = vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap);
97 return e->used += need;
101 esprintf(char **result, const char *fmt, ...)
108 return ECORE_CONFIG_ERR_FAIL;
111 need = vsnprintf(NULL, 0, fmt, ap) + 1;
113 n = malloc(need + 1);
118 need = vsnprintf(n, need, fmt, ap);
130 return ECORE_CONFIG_ERR_OOM;
133 /*****************************************************************************/