summaryrefslogtreecommitdiff
path: root/legacy/ecore
diff options
context:
space:
mode:
authorhandyande <handyande>2006-01-18 12:35:06 +0000
committerhandyande <handyande@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>2006-01-18 12:35:06 +0000
commita35fb4d4a7d1dc5cc2a8ce367ddd6acdd2ea5d81 (patch)
tree3256d8898eba11a3b439858bce0513dd2e757751 /legacy/ecore
parentd2bcbb192bc5ed423f839396c6ceb3fa1ac9c82f (diff)
Sorry Morten, this append func got broken - do not have time to debug, so am rolling it back
SVN revision: 19889
Diffstat (limited to 'legacy/ecore')
-rw-r--r--legacy/ecore/src/lib/ecore_config/ecore_config_util.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/legacy/ecore/src/lib/ecore_config/ecore_config_util.c b/legacy/ecore/src/lib/ecore_config/ecore_config_util.c
index 0a5fc17f09..6d3f7a1057 100644
--- a/legacy/ecore/src/lib/ecore_config/ecore_config_util.c
+++ b/legacy/ecore/src/lib/ecore_config/ecore_config_util.c
@@ -13,6 +13,8 @@
13 13
14#include "ecore_config_private.h" 14#include "ecore_config_private.h"
15 15
16#define CHUNKLEN 4096
17
16/*****************************************************************************/ 18/*****************************************************************************/
17/* STRINGS */ 19/* STRINGS */
18/***********/ 20/***********/
@@ -47,36 +49,46 @@ estring_disown(estring * e)
47int 49int
48estring_appendf(estring * e, const char *fmt, ...) 50estring_appendf(estring * e, const char *fmt, ...)
49{ 51{
50 va_list ap; 52 int need;
51 size_t need; 53 va_list ap;
52 char *p; 54 char *p;
53 55
54 if (!e) 56 if (!e)
55 return ECORE_CONFIG_ERR_FAIL; 57 return ECORE_CONFIG_ERR_FAIL;
56 58
57 if (!e->str) 59 if (!e->str)
58 e->used = e->alloc = 0; 60 {
61 e->used = e->alloc = 0;
62 if (!(e->str = (char *)malloc(e->alloc = 512)))
63 return ECORE_CONFIG_ERR_OOM;
64 }
59 65
66 retry:
60 va_start(ap, fmt); 67 va_start(ap, fmt);
61 need = vsnprintf(NULL, 0, fmt, ap); 68 need = vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap);
62 va_end(ap); 69 va_end(ap);
63 if(need >= (e->alloc - e->used)) 70
71 if ((need >= (e->alloc - e->used)) || (need < 0))
64 { 72 {
65 if( !(p = (char *)realloc( e->str, need + e->used + 1 )) ) 73 if (need < 0)
66 { 74 need = 2 * e->alloc;
75 else
76 need++;
77 need += e->used;
78 need += (CHUNKLEN - (need % CHUNKLEN));
79
80 if (!(p = (char *)realloc(e->str, need)))
81 {
67 free(e->str); 82 free(e->str);
68 e->alloc = e->used = 0; 83 e->alloc = e->used = 0;
69 return ECORE_CONFIG_ERR_OOM; 84 return ECORE_CONFIG_ERR_OOM;
70 } 85 }
71 e->alloc += need + 1; 86 e->alloc = need;
72 e->str = p; 87 e->str = p;
88 goto retry;
73 } 89 }
74 90
75 va_start(ap, fmt); 91 return e->used += need;
76 vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap);
77 va_end(ap);
78
79 return e->used;
80} 92}
81 93
82int 94int