diff options
author | Werner Koch <[email protected]> | 2007-05-15 16:10:48 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-05-15 16:10:48 +0000 |
commit | 5f3bca96826fbaf9c4469a7eedef9294f4d74bfb (patch) | |
tree | dae425970a8c0dd0f77ab62c91b2700dfbaa811e /common/xasprintf.c | |
parent | Preparing 2.0.4 (diff) | |
download | gnupg-5f3bca96826fbaf9c4469a7eedef9294f4d74bfb.tar.gz gnupg-5f3bca96826fbaf9c4469a7eedef9294f4d74bfb.zip |
Use estream_asprintf instead of the GNU asprintf.
Diffstat (limited to 'common/xasprintf.c')
-rw-r--r-- | common/xasprintf.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/common/xasprintf.c b/common/xasprintf.c index 75ae18072..ce013ba63 100644 --- a/common/xasprintf.c +++ b/common/xasprintf.c @@ -25,6 +25,11 @@ #include "util.h" #include "iobuf.h" +#include "estream-printf.h" + +#if !defined(ESTREAM_ASPRINTF_MALLOC) || !defined(ESTREAM_ASPRINTF_FREE) +#error Need to define ESTREAM_ASPRINTF_MALLOC and _FREE +#endif /* Same as asprintf but return an allocated buffer suitable to be freed using xfree. This function simply dies on memory failure, @@ -33,15 +38,13 @@ char * xasprintf (const char *fmt, ...) { va_list ap; - char *buf, *p; + char *buf; va_start (ap, fmt); - if (vasprintf (&buf, fmt, ap) < 0) - log_fatal ("asprintf failed: %s\n", strerror (errno)); + if (estream_vasprintf (&buf, fmt, ap) < 0) + log_fatal ("estream_asprintf failed: %s\n", strerror (errno)); va_end (ap); - p = xstrdup (buf); - free (buf); - return p; + return buf; } /* Same as above but return NULL on memory failure. */ @@ -50,14 +53,12 @@ xtryasprintf (const char *fmt, ...) { int rc; va_list ap; - char *buf, *p; + char *buf; va_start (ap, fmt); - rc = vasprintf (&buf, fmt, ap); + rc = estream_vasprintf (&buf, fmt, ap); va_end (ap); if (rc < 0) return NULL; - p = xtrystrdup (buf); - free (buf); - return p; + return buf; } |