summaryrefslogtreecommitdiff
path: root/misc.h
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2008-02-13 10:20:37 -0800
committerAaron Plattner <aplattner@nvidia.com>2008-02-13 10:20:37 -0800
commitece22163b2913af4823bc4aad397a7e32dc5d4e0 (patch)
tree6fed87d929401b49319a7f23ab61ce2180e71196 /misc.h
parentb581a5923ce164af5c8cd5634f4cba4fd098f711 (diff)
1.0-71671.0-7167
Diffstat (limited to 'misc.h')
-rw-r--r--misc.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/misc.h b/misc.h
index 74b3e4b..532fc5a 100644
--- a/misc.h
+++ b/misc.h
@@ -30,10 +30,45 @@
#include <stdio.h>
#include <stdarg.h>
+#include <stdlib.h>
#include "nvidia-installer.h"
#include "command-list.h"
+/*
+ * NV_VSNPRINTF() - takes a fmt string, and uses vsnprintf to build
+ * the resulting string whic it assigns to buf. The caller of this
+ * function is responsible for freeing the returned string.
+ */
+#define NV_VSNPRINTF(buf, fmt) \
+do { \
+ if (!fmt) { \
+ (buf) = NULL; \
+ } else { \
+ va_list ap; \
+ int len, current_len = NV_LINE_LEN; \
+ \
+ (buf) = malloc(current_len); \
+ \
+ while (1) { \
+ va_start(ap, fmt); \
+ len = vsnprintf((buf), current_len, (fmt), ap); \
+ va_end(ap); \
+ \
+ if ((len > -1) && (len < current_len)) { \
+ break; \
+ } else if (len > -1) { \
+ current_len = len + 1; \
+ } else { \
+ current_len += NV_LINE_LEN; \
+ } \
+ \
+ (buf) = realloc(buf, current_len); \
+ } \
+ } \
+} while (0)
+
+
void *nvalloc(size_t size);
void *nvrealloc(void *ptr, size_t size);
char *nvstrdup(const char *s);