diff options
author | Zev Weiss <zev@bewilderbeest.net> | 2016-10-16 01:14:51 -0500 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2016-10-20 07:53:57 -0700 |
commit | 39ee80d53f41b05ef1f483363e8e535db8137f90 (patch) | |
tree | abb0e5d9e4b0fc35887fed81e26e3a599c2198f6 | |
parent | 899b5189ec67bdefd2e294307a9be80de757583e (diff) | |
download | grep-39ee80d53f41b05ef1f483363e8e535db8137f90.tar.gz |
grep: use 'j' intmax_t printf length modifier if supported
* configure.ac: Use gl_PRINTF_SIZES_C99 to test printf and
(conditionally) define HAVE_PRINTF_C99_SIZES.
* src/grep.c (print_offset): Use printf("%j...") for printing
[u]intmax_t if HAVE_PRINTF_C99_SIZES is defined; otherwise continue
using the existing hand-rolled loop.
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/grep.c | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 8a20317e..0dd4d849 100644 --- a/configure.ac +++ b/configure.ac @@ -206,6 +206,12 @@ fi gl_FUNC_PCRE +gl_PRINTF_SIZES_C99 +if test "$gl_cv_func_printf_sizes_c99" = yes; then + AC_DEFINE([HAVE_PRINTF_C99_SIZES], [1], + [Define to 1 if printf formats %j, %z, %t and %L work.]) +fi + case $host_os in mingw*) suffix=w32 ;; *) suffix=posix ;; @@ -1074,6 +1074,7 @@ print_sep (char sep) static void print_offset (uintmax_t pos, int min_width, const char *color) { +#if !HAVE_PRINTF_C99_SIZES /* Do not rely on printf to print pos, since uintmax_t may be longer than long, and long long is not portable. */ @@ -1091,9 +1092,14 @@ print_offset (uintmax_t pos, int min_width, const char *color) if (align_tabs) while (--min_width >= 0) *--p = ' '; +#endif /* !HAVE_PRINTF_C99_SIZES */ pr_sgr_start_if (color); +#if HAVE_PRINTF_C99_SIZES + printf_errno ("%*ju", align_tabs ? min_width : 0, pos); +#else fwrite_errno (p, 1, buf + sizeof buf - p); +#endif pr_sgr_end_if (color); } |