From 7e1d5d6f6a1390a1ff4f4bcf2484a629b113ae23 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Mon, 13 Nov 2006 09:32:28 +0000 Subject: [PATCH] - The printf() family no longer adds a 0 or 0x prefix if the alternate conversion modifier is present for the %o and %x conversions and the value to be converted is 0 already. Put another way, printf("%#x %#o",0,0); now prints "0 0". This required another change so that %p always includes the 0x prefix even if the pointer involved is a NULL pointer. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15162 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 6 ++++++ library/stdio_vfprintf.c | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/library/changes b/library/changes index 00a3474..ebd3d62 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,9 @@ +- The printf() family no longer adds a 0 or 0x prefix if the alternate + conversion modifier is present for the %o and %x conversions and the + value to be converted is 0 already. Put another way, printf("%#x %#o",0,0); + now prints "0 0". This required another change so that %p always includes + the 0x prefix even if the pointer involved is a NULL pointer. + - readlink() no longer sort-of-works for files and directories. It now only works for soft linked objects and returns an error for everything else. This is based upon a fix by Peter Bengtsson. Thank you very much! diff --git a/library/stdio_vfprintf.c b/library/stdio_vfprintf.c index 7237227..b9d4593 100644 --- a/library/stdio_vfprintf.c +++ b/library/stdio_vfprintf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vfprintf.c,v 1.24 2006-09-25 14:51:15 obarthel Exp $ + * $Id: stdio_vfprintf.c,v 1.25 2006-11-13 09:32:28 obarthel Exp $ * * :ts=4 * @@ -580,7 +580,7 @@ vfprintf(FILE * stream,const char * format, va_list arg) conversion_type = 'x'; - SET_FLAG(format_flags,FORMATF_AlternateConversion); + SET_FLAG(format_flags,FORMATF_HexPrefix); fill_character = '0'; minimum_field_width = 8; @@ -1269,6 +1269,16 @@ vfprintf(FILE * stream,const char * format, va_list arg) const char * digit_encoding; int radix; + /* Only add the zero (%o) or hex (%x) prefix if the value to + be converted is non-zero. */ + if(FLAG_IS_SET(format_flags,FORMATF_AlternateConversion) && v != 0) + { + if(conversion_type == 'o') + SET_FLAG(format_flags,FORMATF_ZeroPrefix); + else if (conversion_type == 'x') + SET_FLAG(format_flags,FORMATF_HexPrefix); + } + if(conversion_type == 'o') radix = 8; else if (conversion_type == 'x') @@ -1291,14 +1301,6 @@ vfprintf(FILE * stream,const char * format, va_list arg) } while(v > 0 && buffer < output_buffer); - if(FLAG_IS_SET(format_flags,FORMATF_AlternateConversion)) - { - if(conversion_type == 'o') - SET_FLAG(format_flags,FORMATF_ZeroPrefix); - else if (conversion_type == 'x') - SET_FLAG(format_flags,FORMATF_HexPrefix); - } - while(output_len < precision && output_buffer > buffer) { output_buffer--;