From: Eric Blake Date: Wed, 11 Jun 2008 21:02:20 +0000 (-0600) Subject: od: use gnulib printf replacement as necessary X-Git-Tag: v7.0~186 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bbbc35c9ed194b0d458f2a2827dfbceb9056ef7d;p=platform%2Fupstream%2Fcoreutils.git od: use gnulib printf replacement as necessary * src/od.c (includes): Add xprintf.h. (PRINT_TYPE): New macro, using xprintf instead of printf. (print_s_char, print_char, print_s_short, print_short, print_int) (print_long, print_long_long, print_float, print_double) (print_long_double): Factor into PRINT_TYPE macro. (print_named_ascii, print_ascii): Use xprintf. * NEWS: Mention this as a bug fix. --- diff --git a/NEWS b/NEWS index ce14695..750b15e 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,11 @@ GNU coreutils NEWS -*- outline -*- md5sum now accepts the new option, --quiet, to suppress the printing of 'OK' messages. sha1sum, sha224sum, sha384sum, and sha512sum accept it, too. +** Bug fixes + + od no longer suffers from platform bugs in printf(3). This is + probably most noticeable when using 'od -tfL' to print long doubles. + ** Improvements Improved support for access control lists (ACLs): On MacOS X, Solaris 7..10, diff --git a/src/od.c b/src/od.c index 830f2ab..0c95322 100644 --- a/src/od.c +++ b/src/od.c @@ -25,6 +25,7 @@ #include "system.h" #include "error.h" #include "quote.h" +#include "xprintf.h" #include "xstrtol.h" /* The official name of this program (e.g., no `g' prefix). */ @@ -385,95 +386,28 @@ implies 32. By default, od uses -A o -t oS -w16.\n\ /* Define the print functions. */ -static void -print_s_char (size_t n_bytes, void const *block, char const *fmt_string) -{ - signed char const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} - -static void -print_char (size_t n_bytes, void const *block, char const *fmt_string) -{ - unsigned char const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} - -static void -print_s_short (size_t n_bytes, void const *block, char const *fmt_string) -{ - short int const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} - -static void -print_short (size_t n_bytes, void const *block, char const *fmt_string) -{ - unsigned short int const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); +#define PRINT_TYPE(N, T) \ +static void \ +N (size_t n_bytes, void const *block, char const *fmt_string) \ +{ \ + T const *p = block; \ + size_t i; \ + for (i = n_bytes / sizeof *p; i != 0; i--) \ + xprintf (fmt_string, *p++); \ } -static void -print_int (size_t n_bytes, void const *block, char const *fmt_string) -{ - unsigned int const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} +PRINT_TYPE (print_s_char, signed char) +PRINT_TYPE (print_char, unsigned char) +PRINT_TYPE (print_s_short, short int) +PRINT_TYPE (print_short, unsigned short int) +PRINT_TYPE (print_int, unsigned int) +PRINT_TYPE (print_long, unsigned long int) +PRINT_TYPE (print_long_long, unsigned_long_long_int) +PRINT_TYPE (print_float, float) +PRINT_TYPE (print_double, double) +PRINT_TYPE (print_long_double, long double) -static void -print_long (size_t n_bytes, void const *block, char const *fmt_string) -{ - unsigned long int const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} - -static void -print_long_long (size_t n_bytes, void const *block, char const *fmt_string) -{ - unsigned_long_long_int const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} - -static void -print_float (size_t n_bytes, void const *block, char const *fmt_string) -{ - float const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} - -static void -print_double (size_t n_bytes, void const *block, char const *fmt_string) -{ - double const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} - -static void -print_long_double (size_t n_bytes, void const *block, char const *fmt_string) -{ - long double const *p = block; - size_t i; - for (i = n_bytes / sizeof *p; i != 0; i--) - printf (fmt_string, *p++); -} +#undef PRINT_TYPE static void dump_hexl_mode_trailer (size_t n_bytes, const char *block) @@ -511,7 +445,7 @@ print_named_ascii (size_t n_bytes, void const *block, s = buf; } - printf (" %3s", s); + xprintf (" %3s", s); } } @@ -566,7 +500,7 @@ print_ascii (size_t n_bytes, void const *block, s = buf; } - printf (" %3s", s); + xprintf (" %3s", s); } }