From 8ad6a4a39b9e011b35b61d4113dedfbe2a9428c4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 20 Oct 2003 10:51:59 +0000 Subject: [PATCH] Portability to HP-UX 10, found by Jim Meyering. --- lib/ChangeLog | 4 ++++ lib/vasnprintf.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 885e93c50c..85a79f8980 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2003-10-19 Jim Meyering + + * vasnprintf.c (vasnprintf): Work around losing snprintf on HPUX 10.20. + 2003-10-16 Paul Eggert * getgroups.c: Include , . diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 9c701f1c61..246c75bdfa 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -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 -- 2.30.2