diff options
author | Jim Meyering <jim@meyering.net> | 2003-10-19 20:59:02 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-10-19 20:59:02 +0000 |
commit | fd1e5aba83ef2efb0a9c5b5d5eeddb3533266ccb (patch) | |
tree | f245d3d5a9b20a046d19b212caa3ec3e1f9c81f7 /lib | |
parent | 14dd23ac241e83738883a22e92bc964a6e1afd54 (diff) | |
download | coreutils-fd1e5aba83ef2efb0a9c5b5d5eeddb3533266ccb.tar.xz |
(vasnprintf): Work around losing snprintf on e.g. HPUX 10.20.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vasnprintf.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 9c701f1c6..f416c1240 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -707,6 +707,22 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) p[1] = '\0'; continue; } + else if (retcount < 0) + { + /* The system's snprintf is sorely deficient: + it doesn't recognize the `%n' directive, and it + returns -1 (rather than the length that would + have been required) when the buffer is too small. + This is the case at with least HPUX 10.20. + Double the memory allocation. */ + size_t n = allocated; + if (n < 2 * allocated) + { + n = 2 * allocated; + ENSURE_ALLOCATION (n); + continue; + } + } count = retcount; } #endif |