]> git.tuebingen.mpg.de Git - osl.git/commitdiff
Kill the VSPRINTF macro.
authorAndre Noll <maan@systemlinux.org>
Mon, 26 May 2008 21:06:48 +0000 (23:06 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 26 May 2008 21:06:48 +0000 (23:06 +0200)
It has only one user, make_message(), so move it there.

log.h
osl.c

diff --git a/log.h b/log.h
index dfb05652a56e6ae35c612bef0a34bb6d6dd81b1b..9c3bf4ba6eaf2d398e52cb4aadfad36bb7c48434 100644 (file)
--- a/log.h
+++ b/log.h
 /** \endcond */
 
 __printf_2_3 void __log(int, const char*, ...);
 /** \endcond */
 
 __printf_2_3 void __log(int, const char*, ...);
-
-/**
- * Write a log 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 = malloc(size); \
-       if (p) { \
-               while (1) { \
-                       char *q; \
-                       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 */ \
-                       q = realloc(p, size); \
-                       if (!q) { \
-                               free(p); \
-                               p = NULL; \
-                               break; \
-                       } \
-               } \
-       } \
-}
diff --git a/osl.c b/osl.c
index 31f49a231f5f8e99ead466caf72b815c0ff8ffae..5786939088bf9ef0147694fca40be43f320d6b7e 100644 (file)
--- a/osl.c
+++ b/osl.c
  */
 static __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...)
 {
  */
 static __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...)
 {
-       char *msg;
+       int n;
+       size_t size = 100;
+       char *p = malloc(size);
 
 
-       VSPRINTF(fmt, msg);
-       return msg;
+       if (!p)
+               return NULL;
+       while (1) {
+               char *q;
+               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 */
+               q = realloc(p, size);
+               if (!q) {
+                       free(p);
+                       return NULL;
+               }
+       }
+       return p;
 }
 
 /**
 }
 
 /**