On Fri, 30.03.12 17:20, Frederic Crozat (fcro...@suse.com) wrote: > >From 5008080dda662208278c159213adbd5211496043 Mon Sep 17 00:00:00 2001 > From: Frederic Crozat <fcro...@suse.com> > Date: Thu, 29 Mar 2012 17:53:41 +0200 > Subject: [PATCH 1/2] macro: add newdup macro, equivalent of new + memdup but > type-safe > > --- > src/macro.h | 1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/src/macro.h b/src/macro.h > index 19f259e..a85e72d 100644 > --- a/src/macro.h > +++ b/src/macro.h > @@ -137,6 +137,7 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { > > #define memzero(x,l) (memset((x), 0, (l))) > #define zero(x) (memzero(&(x), sizeof(x))) > +#define newdup(x,l) ( (x= new(typeof(*l),1)) ? memcpy((x),(l),sizeof(*l)) : > NULL)
Hmm, I was more thinking of a definition much closer to new() and new0(), without typeof, but with allowing allocation of an array #define newdup(t, p, n) ((t*)memdup(p,sizeof(t)*(n))) Lennart -- Lennart Poettering - Red Hat, Inc. _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel