]> git.tuebingen.mpg.de Git - dss.git/commitdiff
str.c: Get rid of VSPRINTF macro.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 3 Jan 2015 16:54:36 +0000 (16:54 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 6 Jan 2015 19:55:32 +0000 (20:55 +0100)
It has only one user, make_message(), so it's simpler to include the
code there.

str.c

diff --git a/str.c b/str.c
index ff8f02a4846af402c71b8a2818f2db7fceedfde8..557eaa38ca6352dab2c435ae619ef0fc60700047 100644 (file)
--- a/str.c
+++ b/str.c
 #include "err.h"
 #include "str.h"
 
-/**
- * Write a message to a dynamically allocated string.
- *
- * \param fmt Usual format string.
- * \param p Result pointer.
- *
- * \sa printf(3). */
-#define VSPRINTF(fmt, p) \
-{ \
-       int n; \
-       size_t size = 100; \
-       p = dss_malloc(size); \
-       while (1) { \
-               va_list ap; \
-               /* Try to print in the allocated space. */ \
-               va_start(ap, fmt); \
-               n = vsnprintf(p, size, fmt, ap); \
-               va_end(ap); \
-               /* If that worked, return the string. */ \
-               if (n > -1 && n < size) \
-                       break; \
-               /* Else try again with more space. */ \
-               if (n > -1) /* glibc 2.1 */ \
-                       size = n + 1; /* precisely what is needed */ \
-               else /* glibc 2.0 */ \
-                       size *= 2; /* twice the old size */ \
-               p = dss_realloc(p, size); \
-       } \
-}
-
 /**
  * dss' version of realloc().
  *
@@ -165,8 +135,27 @@ __must_check __malloc char *dss_strdup(const char *s)
 __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...)
 {
        char *msg;
+       size_t size = 100;
+
+       msg = dss_malloc(size);
+       while (1) {
+               int n;
+               va_list ap;
 
-       VSPRINTF(fmt, msg);
+               /* Try to print in the allocated space. */
+               va_start(ap, fmt);
+               n = vsnprintf(msg, size, fmt, ap);
+               va_end(ap);
+               /* If that worked, return the string. */
+               if (n > -1 && n < size)
+                       break;
+               /* Else try again with more space. */
+               if (n > -1) /* glibc 2.1 */
+                       size = n + 1; /* precisely what is needed */
+               else /* glibc 2.0 */
+                       size *= 2; /* twice the old size */
+               msg = dss_realloc(msg, size);
+       }
        return msg;
 }