]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
make asprintf work on broken solaris systems ...
authorAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 01:51:14 +0000 (02:51 +0100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 01:51:14 +0000 (02:51 +0100)
util.c

diff --git a/util.c b/util.c
index 461e93be6c6698c00109ce757c1bbbfc0adb85c0..883d910f11ff5f4ffe71f04343dabe19e27029b2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -78,19 +78,23 @@ 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
 */
 int x_asprintf(char **ptr, const char *format, ...)
 {
        va_list ap;
        int ret;
-       
+       char tmp[2];
+
        *ptr = NULL;
        va_start(ap, format);
-       ret = vsnprintf(NULL, 0, format, ap);
+       ret = vsnprintf(tmp, 1, format, ap);
        va_end(ap);
 
-       if (ret <= 0) {
-               fatal("Bad vsnprintf implementation!?\n");
+       if (ret <= 1) {
+               cc_log("Bad vsnprintf implementation (%d)!?\n", ret);
+               exit(1);
        }
 
        *ptr = (char *)malloc(ret+1);