summaryrefslogtreecommitdiff
path: root/misc.h
diff options
context:
space:
mode:
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);