From 3e151f8c764a5f1116fae3bea87f3d4474dc686a Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 28 Nov 2012 14:32:44 +0000 Subject: add xasprintf() for upcoming changes. --- calmwm.h | 3 +++ xmalloc.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/calmwm.h b/calmwm.h index 5085807..1abcbef 100644 --- a/calmwm.h +++ b/calmwm.h @@ -492,6 +492,9 @@ void u_spawn(char *); void *xcalloc(size_t, size_t); void *xmalloc(size_t); char *xstrdup(const char *); +int xasprintf(char **, const char *, ...) + __attribute__((__format__ (printf, 2, 3))) + __attribute__((__nonnull__ (2))); /* Externs */ extern Display *X_Dpy; diff --git a/xmalloc.c b/xmalloc.c index d0697fa..0480c73 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -69,3 +69,19 @@ xstrdup(const char *str) return (p); } + +int +xasprintf(char **ret, const char *fmt, ...) +{ + va_list ap; + int i; + + va_start(ap, fmt); + i = vasprintf(ret, fmt, ap); + va_end(ap); + + if (i < 0 || *ret == NULL) + err(1, "asprintf"); + + return (i); +} -- cgit 1.4.1