aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/fmt/dofmt.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-05-22 14:54:34 +0000
committerrsc <devnull@localhost>2006-05-22 14:54:34 +0000
commite17e1a71c2923717723f7038d6e123b6452e0b13 (patch)
treead086b35c4d054b75d17fb621e322d7b6b883c98 /src/lib9/fmt/dofmt.c
parentf8955f181efa175573ccecc71a19464fdba50ef5 (diff)
downloadplan9port-e17e1a71c2923717723f7038d6e123b6452e0b13.tar.gz
plan9port-e17e1a71c2923717723f7038d6e123b6452e0b13.tar.bz2
plan9port-e17e1a71c2923717723f7038d6e123b6452e0b13.zip
incorporate changes from Google
Diffstat (limited to 'src/lib9/fmt/dofmt.c')
-rw-r--r--src/lib9/fmt/dofmt.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib9/fmt/dofmt.c b/src/lib9/fmt/dofmt.c
index 06f0a3d9..74697eb5 100644
--- a/src/lib9/fmt/dofmt.c
+++ b/src/lib9/fmt/dofmt.c
@@ -1,4 +1,6 @@
/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
+/* Copyright (c) 2004 Google Inc.; see LICENSE */
+
#include <stdarg.h>
#include <string.h>
#include "plan9.h"
@@ -454,11 +456,26 @@ __ifmt(Fmt *f)
}
}
if(n == 0){
- *p-- = '0';
- n = 1;
- if(fl & FmtApost)
- __needsep(&ndig, &grouping);
- fl &= ~FmtSharp; /* ??? */
+ /*
+ * "The result of converting a zero value with
+ * a precision of zero is no characters." - ANSI
+ *
+ * "For o conversion, # increases the precision, if and only if
+ * necessary, to force the first digit of the result to be a zero
+ * (if the value and precision are both 0, a single 0 is printed)." - ANSI
+ */
+ if(!(fl & FmtPrec) || f->prec != 0 || (f->r == 'o' && (fl & FmtSharp))){
+ *p-- = '0';
+ n = 1;
+ if(fl & FmtApost)
+ __needsep(&ndig, &grouping);
+ }
+
+ /*
+ * Zero values don't get 0x.
+ */
+ if(f->r == 'x' || f->r == 'X')
+ fl &= ~FmtSharp;
}
for(w = f->prec; n < w && p > buf+3; n++){
if((fl & FmtApost) && __needsep(&ndig, &grouping)){