diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-11-12 23:32:48 +0100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-11-13 00:15:46 +0100 |
commit | 166927fd410823eec8a7b2472463db51e0e6fef5 (patch) | |
tree | 6ed8e9b9ad379acf14bdb15f95afd9a367c811ae | |
parent | Remove leftover if statement from sync. (diff) | |
download | openssh-166927fd410823eec8a7b2472463db51e0e6fef5.tar.xz openssh-166927fd410823eec8a7b2472463db51e0e6fef5.zip |
upstream: add xvasprintf()
OpenBSD-Commit-ID: e5e3671c05c121993b034db935bce1a7aa372247
-rw-r--r-- | xmalloc.c | 21 | ||||
-rw-r--r-- | xmalloc.h | 4 |
2 files changed, 17 insertions, 8 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.35 2019/06/06 05:13:13 otto Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.36 2019/11/12 22:32:48 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -96,17 +96,24 @@ xstrdup(const char *str) } int +xvasprintf(char **ret, const char *fmt, va_list ap) +{ + int i; + + i = vasprintf(ret, fmt, ap); + if (i < 0 || *ret == NULL) + fatal("xvasprintf: could not allocate memory"); + return i; +} + +int xasprintf(char **ret, const char *fmt, ...) { va_list ap; int i; va_start(ap, fmt); - i = vasprintf(ret, fmt, ap); + i = xvasprintf(ret, fmt, ap); va_end(ap); - - if (i < 0 || *ret == NULL) - fatal("xasprintf: could not allocate memory"); - - return (i); + return i; } @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.h,v 1.18 2019/06/06 05:13:13 otto Exp $ */ +/* $OpenBSD: xmalloc.h,v 1.19 2019/11/12 22:32:48 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -24,3 +24,5 @@ char *xstrdup(const char *); int xasprintf(char **, const char *, ...) __attribute__((__format__ (printf, 2, 3))) __attribute__((__nonnull__ (2))); +int xvasprintf(char **, const char *, va_list) + __attribute__((__nonnull__ (2))); |