]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
aix has an even worse vsnprintf() - cope with that too
authorAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 02:17:02 +0000 (03:17 +0100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 02:17:02 +0000 (03:17 +0100)
ccache.h
util.c

index 0f5c6627953636d26f3959c86e63d7029995b781..07dc06ef07d21207f85b8360524c873236e5393b 100644 (file)
--- 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 883d910f11ff5f4ffe71f04343dabe19e27029b2..f3441f6766e1abbc78fd9f89bdf87e8b7f234c29 100644 (file)
--- 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);
 }
 
 /*