[GRASS-SVN] r50384 - grass/trunk/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 22 15:25:48 EST 2012


Author: mmetz
Date: 2012-01-22 12:25:48 -0800 (Sun, 22 Jan 2012)
New Revision: 50384

Modified:
   grass/trunk/lib/gis/asprintf.c
Log:
libgis: change fn names to better refelct what they do

Modified: grass/trunk/lib/gis/asprintf.c
===================================================================
--- grass/trunk/lib/gis/asprintf.c	2012-01-22 20:24:57 UTC (rev 50383)
+++ grass/trunk/lib/gis/asprintf.c	2012-01-22 20:25:48 UTC (rev 50384)
@@ -29,9 +29,10 @@
  * \brief Safe replacement for <i>asprintf()</i>.
  *
  * Allocate a string large enough to hold the new output, including the 
- * terminating NULL, and returns a pointer to the first parameter. The 
- * pointer should be passed to <i>G_free()</i> to release the allocated 
- * storage when it is no longer needed.
+ * terminating NULL, and return the number of characters printed. The 
+ * pointer out is set to the output string and should be passed to 
+ * <i>G_free()</i> to release the allocated storage when it is no longer 
+ * needed.
  *
  * \param[out] out
  * \param[in] fmt
@@ -77,12 +78,14 @@
 #endif /* G_asprintf */
 
 /**
- * \brief Safe replacement for <i>asprintf()</i>.
+ * \brief Reallocating version of <i>asprintf()</i>.
  *
- * (Re-)Allocate a string large enough to hold the new output, including the 
- * terminating NULL, and returns a pointer to the first parameter. The 
- * pointer should be passed to <i>G_free()</i> to release the allocated 
- * storage when it is no longer needed.
+ * Reallocate a string large enough to hold the output, including the 
+ * terminating NULL, and return the number of characters printed.  
+ * Contrary to <i>G_asprintf()</i>, any existing buffer pointed to by 
+ * out of size osize is used to hold the output and enlarged if 
+ * necessary. This is usefull when <i>G_rasprintf</i> is called many 
+ * times in a loop.
  *
  * \param[out] out
  * \param[out] size
@@ -90,39 +93,39 @@
  * \return number of bytes written
  */
 
-int G_vasprintf2(char **out, size_t *size, const char *fmt, va_list ap)
+int G_vsnprintf(char **out, size_t *osize, const char *fmt, va_list ap)
 {
     char *buf = *out;
     int count;
-    size_t s = *size;
+    size_t size = *osize;
     
-    if (s < strlen(fmt) + 50) {
-	s = strlen(fmt) + 50;
-	buf = G_realloc(buf, s);
+    if (size < strlen(fmt) + 50) {
+	size = strlen(fmt) + 50;
+	buf = G_realloc(buf, size);
     }
 
     for (;;) {
-	count = vsnprintf(buf, s, fmt, ap);
-	if (count >= 0 && count < s)
+	count = vsnprintf(buf, size, fmt, ap);
+	if (count >= 0 && count < size)
 	    break;
-	s *= 2;
-	buf = G_realloc(buf, s);
+	size *= 2;
+	buf = G_realloc(buf, size);
     }
 
     buf = G_realloc(buf, count + 1);
     *out = buf;
-    *size = s;
+    *osize = size;
 
     return count;
 }
 
-int G_asprintf2(char **out, size_t *size, const char *fmt, ...)
+int G_rasprintf(char **out, size_t *size, const char *fmt, ...)
 {
     va_list ap;
     int count;
 
     va_start(ap, fmt);
-    count = G_vasprintf2(out, size, fmt, ap);
+    count = G_vsnprintf(out, size, fmt, ap);
     va_end(ap);
 
     return count;



More information about the grass-commit mailing list