8 #include <stdlib.h> /* malloc(), free() */
10 #include <string.h> /* str...() */
12 #include <stdarg.h> /* varargs in sprintf/appendf */
15 #include "ecore_private.h"
17 #include "Ecore_Config.h"
18 #include "ecore_config_util.h"
20 #include "ecore_config_private.h"
24 /*****************************************************************************/
31 estring *e = malloc(sizeof(estring));
35 memset(e, 0, sizeof(estring));
36 if ((size > 0) && (e->str = malloc(size)))
43 estring_disown(estring * e)
56 estring_appendf(estring * e, const char *fmt, ...)
63 return ECORE_CONFIG_ERR_FAIL;
67 e->used = e->alloc = 0;
68 if (!(e->str = (char *)malloc(e->alloc = CHUNKLEN)))
69 return ECORE_CONFIG_ERR_OOM;
73 need = vsnprintf(NULL, 0, fmt, ap);
76 if (need >= (e->alloc - e->used))
78 e->alloc = e->used + need + (CHUNKLEN - (need % CHUNKLEN));
80 if (!(p = (char *)realloc(e->str, e->alloc)))
83 e->alloc = e->used = 0;
84 return ECORE_CONFIG_ERR_OOM;
90 need = vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap);
93 return e->used += need;
97 esprintf(char **result, const char *fmt, ...)
104 return ECORE_CONFIG_ERR_FAIL;
107 need = vsnprintf(NULL, 0, fmt, ap) + 1;
109 n = malloc(need + 1);
114 need = vsnprintf(n, need, fmt, ap);
126 return ECORE_CONFIG_ERR_OOM;
129 /*****************************************************************************/