# HG changeset patch
# User Keir Fraser <keir@xxxxxxx>
# Date 1295018484 0
# Node ID 7e42363f9005e948dfdd3e76d6d72635c2edce5b
# Parent 47d67a64a2d2a1a41e5588b0cbdf179958d1363d
hvmloader: Fixes to printf() implementation.
1. Remove unportable O and D format specifiers
2. Fix X format specifier to print upper-case hex characters
3. Fix d format specifier to print -ve numbers
4. Fix handling of int vs. long (although not actually an issue
for the i386 compile target)
5. Don't use the antiquated C 'register' type attribute.
Signed-off-by: Keir Fraser <keir@xxxxxxx>
---
tools/firmware/hvmloader/util.c | 43 +++++++++++++++++++++++++---------------
1 files changed, 27 insertions(+), 16 deletions(-)
diff -r 47d67a64a2d2 -r 7e42363f9005 tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c Fri Jan 14 15:18:02 2011 +0000
+++ b/tools/firmware/hvmloader/util.c Fri Jan 14 15:21:24 2011 +0000
@@ -425,10 +425,10 @@ static char *printnum(char *p, unsigned
static void _doprint(void (*put)(char), const char *fmt, va_list ap)
{
- register char *str, c;
+ char *str, c;
int lflag, zflag, nflag;
char buffer[17];
- unsigned value;
+ unsigned long value;
int i, slen, pad;
for ( ; *fmt != '\0'; fmt++ )
@@ -457,29 +457,40 @@ static void _doprint(void (*put)(char),
lflag = 1;
c = *++fmt;
}
- if ( (c == 'd') || (c == 'u') || (c == 'o') || (c == 'x') )
+ if ( (c == 'd') || (c == 'u') || (c == 'o') ||
+ (c == 'x') || (c == 'X') )
{
if ( lflag )
- value = va_arg(ap, unsigned);
+ {
+ value = va_arg(ap, unsigned long);
+ if ( (c == 'd') && ((long)value < 0) )
+ {
+ value = -value;
+ put('-');
+ }
+ }
else
- value = (unsigned) va_arg(ap, unsigned int);
+ {
+ value = va_arg(ap, unsigned int);
+ if ( (c == 'd') && ((int)value < 0) )
+ {
+ value = -(int)value;
+ put('-');
+ }
+ }
str = buffer;
printnum(str, value,
- c == 'o' ? 8 : (c == 'x' ? 16 : 10));
- goto printn;
- }
- else if ( (c == 'O') || (c == 'D') || (c == 'X') )
- {
- value = va_arg(ap, unsigned);
- str = buffer;
- printnum(str, value,
- c == 'O' ? 8 : (c == 'X' ? 16 : 10));
- printn:
+ c == 'o' ? 8 : ((c == 'x') || (c == 'X') ? 16 : 10));
slen = strlen(str);
for ( i = pad - slen; i > 0; i-- )
put(zflag ? '0' : ' ');
while ( *str )
- put(*str++);
+ {
+ char ch = *str++;
+ if ( (ch >= 'a') && (c == 'X') )
+ ch += 'A'-'a';
+ put(ch);
+ }
}
else if ( c == 's' )
{
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|