Portability to HP-UX 10, found by Jim Meyering.
authorBruno Haible <bruno@clisp.org>
Mon, 20 Oct 2003 10:51:59 +0000 (10:51 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 20 Oct 2003 10:51:59 +0000 (10:51 +0000)
lib/ChangeLog
lib/vasnprintf.c

index 885e93c50c4df4d2ccb6bcee89fcde09e21e8857..85a79f898089beb7d9cd2fc7cc73ae945086379a 100644 (file)
@@ -1,3 +1,7 @@
+2003-10-19  Jim Meyering  <jim@meyering.net>
+
+       * vasnprintf.c (vasnprintf): Work around losing snprintf on HPUX 10.20.
+
 2003-10-16  Paul Eggert  <eggert@twinsun.com>
 
        * getgroups.c: Include <errno.h>, <stdlib.h>.
index 9c701f1c6140872b58721dbc8f9cbcf4b62c0b90..246c75bdfa0fe63ecee2b8839a7f2cdd7988a3f2 100644 (file)
@@ -707,7 +707,23 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
                            p[1] = '\0';
                            continue;
                          }
-                       count = retcount;
+                       else
+                         {
+                           /* Look at the snprintf() return value.  */
+                           if (retcount < 0)
+                             {
+                               /* HP-UX 10.20 snprintf() is doubly deficient:
+                                  It doesn't understand the '%n' directive,
+                                  *and* it returns -1 (rather than the length
+                                  that would have been required) when the
+                                  buffer is too small.  */
+                               size_t bigger_need = 2 * allocated + 12;
+                               ENSURE_ALLOCATION (bigger_need);
+                               continue;
+                             }
+                           else
+                             count = retcount;
+                         }
                      }
 #endif