From 2d698b6e42d8dca191ac795ef5dba3bf62496eec Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 9 Apr 2010 16:13:32 -0700 Subject: Integrate bash 3.2 version This is merge of current Debian stable (Lenny) version of Bash with Vyatta changes. --- lib/sh/snprintf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/sh/snprintf.c') diff --git a/lib/sh/snprintf.c b/lib/sh/snprintf.c index 114135f..4a96474 100644 --- a/lib/sh/snprintf.c +++ b/lib/sh/snprintf.c @@ -65,6 +65,7 @@ #define HAVE_PRINTF_A_FORMAT #endif #define HAVE_ISINF_IN_LIBC +#define HAVE_ISNAN_IN_LIBC #define PREFER_STDARG #define HAVE_STRINGIZE #define HAVE_LIMITS_H @@ -370,6 +371,12 @@ static void xfree __P((void *)); for (; (p)->width > 0; (p)->width--) \ PUT_CHAR((p)->pad, p) +/* pad with zeros from decimal precision */ +#define PAD_ZERO(p) \ + if ((p)->precision > 0) \ + for (; (p)->precision > 0; (p)->precision--) \ + PUT_CHAR('0', p) + /* if width and prec. in the args */ #define STAR_ARGS(p) \ do { \ @@ -651,6 +658,10 @@ number(p, d, base) long sd; int flags; + /* An explicit precision turns off the zero-padding flag. */ + if ((p->flags & PF_ZEROPAD) && p->precision >= 0 && (p->flags & PF_DOT)) + p->flags &= ~PF_ZEROPAD; + sd = d; /* signed for ' ' padding in base 10 */ flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0; if (*p->pf == 'X') @@ -668,6 +679,12 @@ number(p, d, base) p->width -= strlen(tmp); PAD_RIGHT(p); + if ((p->flags & PF_DOT) && p->precision > 0) + { + p->precision -= strlen(tmp); + PAD_ZERO(p); + } + switch (base) { case 10: @@ -711,6 +728,10 @@ lnumber(p, d, base) long long sd; int flags; + /* An explicit precision turns off the zero-padding flag. */ + if ((p->flags & PF_ZEROPAD) && p->precision >= 0 && (p->flags & PF_DOT)) + p->flags &= ~PF_ZEROPAD; + sd = d; /* signed for ' ' padding in base 10 */ flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0; if (*p->pf == 'X') @@ -728,6 +749,12 @@ lnumber(p, d, base) p->width -= strlen(tmp); PAD_RIGHT(p); + if ((p->flags & PF_DOT) && p->precision > 0) + { + p->precision -= strlen(tmp); + PAD_ZERO(p); + } + switch (base) { case 10: @@ -881,7 +908,9 @@ isinf(d) #endif return 0; } +#endif +#ifndef HAVE_ISNAN_IN_LIBC static int isnan(d) double d; -- cgit v1.2.3