diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h index a8f1d9f74..555db70a7 100644 --- a/app/cwm/calmwm.h +++ b/app/cwm/calmwm.h @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: calmwm.h,v 1.160 2012/11/28 14:14:44 okan Exp $ + * $OpenBSD: calmwm.h,v 1.161 2012/11/28 14:32:44 okan Exp $ */ #ifndef _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/app/cwm/xmalloc.c b/app/cwm/xmalloc.c index 8e9d22ab2..c278e721f 100644 --- a/app/cwm/xmalloc.c +++ b/app/cwm/xmalloc.c @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: xmalloc.c,v 1.10 2012/11/16 14:15:48 okan Exp $ + * $OpenBSD: xmalloc.c,v 1.11 2012/11/28 14:32:44 okan Exp $ */ #include @@ -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); +}