From ddfdf24b02964364d924ed32123492fb0741fb05 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 20 Sep 2007 07:02:35 +0000 Subject: [PATCH] Add a REPLACE() macro, for manipulating malloced string variables. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1957 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/include/miniobj.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/varnish-cache/include/miniobj.h b/varnish-cache/include/miniobj.h index 3c714be1..cb727c58 100644 --- a/varnish-cache/include/miniobj.h +++ b/varnish-cache/include/miniobj.h @@ -30,10 +30,21 @@ CHECK_OBJ((to), (type_magic)); \ } while (0); -#define CAST_OBJ_NOTNULL(to, from, type_magic) \ +#define CAST_OBJ_NOTNULL(to, from, type_magic) \ do { \ (to) = (from); \ assert((to) != NULL); \ CHECK_OBJ((to), (type_magic)); \ } while (0); +#define REPLACE(ptr, val) \ + do { \ + if ((ptr) != NULL) \ + free(ptr); \ + if ((val) != NULL) { \ + ptr = strdup(val); \ + AN((ptr)); \ + } else { \ + ptr = NULL; \ + } \ + } while (0); -- 2.39.5