From: Andrew Tridgell Date: Wed, 27 Mar 2002 02:17:02 +0000 (+0100) Subject: aix has an even worse vsnprintf() - cope with that too X-Git-Tag: v1.0~39 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9684d92d50430dab2e551ff4d6066452b5cb5d70;p=thirdparty%2Fccache.git aix has an even worse vsnprintf() - cope with that too --- diff --git a/ccache.h b/ccache.h index 0f5c66279..07dc06ef0 100644 --- a/ccache.h +++ b/ccache.h @@ -38,7 +38,7 @@ void fatal(const char *msg); void copy_fd(int fd_in, int fd_out); int create_dir(const char *dir); -int x_asprintf(char **ptr, const char *format, ...); +void x_asprintf(char **ptr, const char *format, ...); char *x_strdup(const char *s); int execute(char **argv, diff --git a/util.c b/util.c index 883d910f1..f3441f676 100644 --- a/util.c +++ b/util.c @@ -78,34 +78,24 @@ int create_dir(const char *dir) /* this is like asprintf() but dies if the malloc fails - note the rather strange use of vsnprintf() to try to make this - work on non C99 systems like Solaris + note that we use vsnprintf in a rather poor way to make this more portable */ -int x_asprintf(char **ptr, const char *format, ...) +void x_asprintf(char **ptr, const char *format, ...) { va_list ap; int ret; - char tmp[2]; + char tmp[1024]; *ptr = NULL; va_start(ap, format); - ret = vsnprintf(tmp, 1, format, ap); + ret = vsnprintf(tmp, sizeof(tmp), format, ap); va_end(ap); - if (ret <= 1) { - cc_log("Bad vsnprintf implementation (%d)!?\n", ret); - exit(1); + if (ret == sizeof(tmp)) { + fatal("vsnprintf - too long\n"); } - *ptr = (char *)malloc(ret+1); - if (! *ptr) { - fatal("out of memory in x_asprintf\n"); - } - va_start(ap, format); - ret = vsnprintf(*ptr, ret+1, format, ap); - va_end(ap); - - return ret; + *ptr = x_strdup(tmp); } /*