summaryrefslogtreecommitdiff
path: root/lib/sh/snprintf.c
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-04-09 16:13:32 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-04-09 16:15:01 -0700
commit2d698b6e42d8dca191ac795ef5dba3bf62496eec (patch)
treeac5e0b67043c50f49160e9fe407435706cf30444 /lib/sh/snprintf.c
parentf1250933e4a2ac09a3d0b25b3877068e12f44da5 (diff)
downloadvyatta-bash-2d698b6e42d8dca191ac795ef5dba3bf62496eec.tar.gz
vyatta-bash-2d698b6e42d8dca191ac795ef5dba3bf62496eec.zip
Integrate bash 3.2 version
This is merge of current Debian stable (Lenny) version of Bash with Vyatta changes.
Diffstat (limited to 'lib/sh/snprintf.c')
-rw-r--r--lib/sh/snprintf.c29
1 files changed, 29 insertions, 0 deletions
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;