summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--src/od.c110
2 files changed, 27 insertions, 88 deletions
diff --git a/NEWS b/NEWS
index ce14695b2..750b15e47 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 830f2abd8..0c95322b3 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);
}
}