From: Ben Pfaff Date: Tue, 13 Jan 2009 22:24:17 +0000 (-0800) Subject: Introduce x2nrealloc() helper function. X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=9ebcf1a3d7524aea36c506f7c0e37bfaa1908dae;p=sliver-openvswitch.git Introduce x2nrealloc() helper function. Crossported from master branch because it is a dependency for svec, which is needed by the switch UI, which is wanted in 0.4. --- diff --git a/lib/util.c b/lib/util.c index 72138a066..abf005d34 100644 --- a/lib/util.c +++ b/lib/util.c @@ -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, ...) { diff --git a/lib/util.h b/lib/util.h index 8dee9b6d4..8172b69e4 100644 --- a/lib/util.h +++ b/lib/util.h @@ -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);