diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2008-02-13 10:20:37 -0800 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2008-02-13 10:20:37 -0800 |
commit | ece22163b2913af4823bc4aad397a7e32dc5d4e0 (patch) | |
tree | 6fed87d929401b49319a7f23ab61ce2180e71196 /misc.h | |
parent | b581a5923ce164af5c8cd5634f4cba4fd098f711 (diff) |
1.0-71671.0-7167
Diffstat (limited to 'misc.h')
-rw-r--r-- | misc.h | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -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); |