Introduce x2nrealloc() helper function.
authorBen Pfaff <blp@nicira.com>
Tue, 13 Jan 2009 22:24:17 +0000 (14:24 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 13 Jan 2009 22:24:35 +0000 (14:24 -0800)
Crossported from master branch because it is a dependency for svec,
which is needed by the switch UI, which is wanted in 0.4.

lib/util.c
lib/util.h

index 72138a0..abf005d 100644 (file)
@@ -118,6 +118,13 @@ xvasprintf(const char *format, va_list args)
     return s;
 }
 
+void *
+x2nrealloc(void *p, size_t *n, size_t s)
+{
+    *n = *n == 0 ? 1 : 2 * *n;
+    return xrealloc(p, *n * s);
+}
+
 char *
 xasprintf(const char *format, ...)
 {
index 8dee9b6..8172b69 100644 (file)
@@ -102,6 +102,7 @@ char *xmemdup0(const char *, size_t);
 char *xstrdup(const char *);
 char *xasprintf(const char *format, ...) PRINTF_FORMAT(1, 2);
 char *xvasprintf(const char *format, va_list) PRINTF_FORMAT(1, 0);
+void *x2nrealloc(void *p, size_t *n, size_t s);
 
 #ifndef HAVE_STRLCPY
 void strlcpy(char *dst, const char *src, size_t size);