Enlightenment CVS committal

Author  : handyande
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_config


Modified Files:
        ecore_config_util.c 


Log Message:
Sorry Morten, this append func got broken - do not have time to debug, so am 
rolling it back
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config_util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ecore_config_util.c 30 Dec 2005 20:10:01 -0000      1.3
+++ ecore_config_util.c 18 Jan 2006 12:35:06 -0000      1.4
@@ -13,6 +13,8 @@
 
 #include "ecore_config_private.h"
 
+#define CHUNKLEN 4096
+
 /*****************************************************************************/
 /* STRINGS */
 /***********/
@@ -47,36 +49,46 @@
 int
 estring_appendf(estring * e, const char *fmt, ...)
 {
-   va_list     ap;
-   size_t      need;
-   char       *p;
+   int                 need;
+   va_list             ap;
+   char               *p;
 
    if (!e)
       return ECORE_CONFIG_ERR_FAIL;
 
    if (!e->str)
-     e->used = e->alloc = 0;
+     {
+       e->used = e->alloc = 0;
+       if (!(e->str = (char *)malloc(e->alloc = 512)))
+          return ECORE_CONFIG_ERR_OOM;
+     }
 
+ retry:
    va_start(ap, fmt);
-   need = vsnprintf(NULL, 0, fmt, ap);
+   need = vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap);
    va_end(ap);
-   if(need >= (e->alloc - e->used))
+
+   if ((need >= (e->alloc - e->used)) || (need < 0))
      {
-       if( !(p = (char *)realloc( e->str, need + e->used + 1 )) )
-          {
+       if (need < 0)
+          need = 2 * e->alloc;
+       else
+          need++;
+       need += e->used;
+       need += (CHUNKLEN - (need % CHUNKLEN));
+
+       if (!(p = (char *)realloc(e->str, need)))
+         {
             free(e->str);
             e->alloc = e->used = 0;
             return ECORE_CONFIG_ERR_OOM;
-          }
-       e->alloc += need + 1;
+         }
+       e->alloc = need;
        e->str = p;
+       goto retry;
      }
 
-   va_start(ap, fmt);
-   vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap);
-   va_end(ap);
-
-   return e->used;
+   return e->used += need;
 }
 
 int




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to