From 18afed0f98d020608c65293ecb9246dab6c58db3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Feb 2017 22:29:58 +0100 Subject: Use %I64* formats with MinGW instead of %ll* formats The MSVC runtime uses the format specified %I64 for 64-bit data types; It does not understand e.g. %llu for unsigned long longs. However, mingw-w64 provides a compatibility mode in its runtime wrapper which can be activated by defining the constant __USE_MINGW_ANSI_STDIO=1 in which case we must refrain from overriding the %ll* formats. This fixes quite a couple of compile warnings when building with the mingw-w64 compiler. Signed-off-by: Johannes Schindelin --- coreutils/expr.c | 2 +- coreutils/factor.c | 4 ++-- coreutils/ls.c | 2 +- coreutils/sum.c | 4 ++-- editors/awk.c | 2 +- include/libbb.h | 9 ++++++++- libbb/xatonum_template.c | 5 +++-- miscutils/dc.c | 2 +- procps/iostat.c | 2 +- procps/mpstat.c | 2 +- shell/math.h | 2 +- 11 files changed, 22 insertions(+), 14 deletions(-) diff --git a/coreutils/expr.c b/coreutils/expr.c index 5d2fbf2f7..639d29a55 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c @@ -84,7 +84,7 @@ #if ENABLE_EXPR_MATH_SUPPORT_64 typedef int64_t arith_t; -#define PF_REZ "ll" +#define PF_REZ LL_FMT #define PF_REZ_TYPE (long long) #define STRTOL(s, e, b) strtoll(s, e, b) #else diff --git a/coreutils/factor.c b/coreutils/factor.c index 205cdc053..8782d3d1e 100644 --- a/coreutils/factor.c +++ b/coreutils/factor.c @@ -161,7 +161,7 @@ static NOINLINE void factorize(wide_t N) } end: if (N > 1) - printf(" %llu", N); + printf(" %"LL_FMT"u", N); bb_putchar('\n'); } @@ -175,7 +175,7 @@ static void factorize_numstr(const char *numstr) N = bb_strtoull(numstr, NULL, 10); if (errno) bb_show_usage(); - printf("%llu:", N); + printf("%"LL_FMT"u:", N); factorize(N); } diff --git a/coreutils/ls.c b/coreutils/ls.c index 6780057da..61b4409a7 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -496,7 +496,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn) lpath = xmalloc_readlink_or_warn(dn->fullname); if (opt & OPT_i) /* show inode# */ - column += printf("%7llu ", (long long) dn->dn_ino); + column += printf("%7"LL_FMT"u ", (long long) dn->dn_ino); //TODO: -h should affect -s too: if (opt & OPT_s) /* show allocated blocks */ column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); diff --git a/coreutils/sum.c b/coreutils/sum.c index c55293dc9..2a91f963c 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c @@ -82,9 +82,9 @@ static unsigned sum_file(const char *file, unsigned type) if (type >= SUM_SYSV) { r = (s & 0xffff) + ((s & 0xffffffff) >> 16); s = (r & 0xffff) + (r >> 16); - printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file); + printf("%u %"LL_FMT"u %s\n", s, (total_bytes + 511) / 512, file); } else - printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file); + printf("%05u %5"OFF_FMT"u %s\n", s, (total_bytes + 1023) / 1024, file); return 1; #undef buf } diff --git a/editors/awk.c b/editors/awk.c index 84ba125cd..e8e2c96f8 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2078,7 +2078,7 @@ static int fmt_num(char *b, int size, const char *format, double n, int int_as_i const char *s = format; if (int_as_int && n == (long long)n) { - r = snprintf(b, size, "%lld", (long long)n); + r = snprintf(b, size, "%"LL_FMT"d", (long long)n); } else { do { c = *s; } while (c && *++s); if (strchr("diouxX", c)) { diff --git a/include/libbb.h b/include/libbb.h index 9313a557a..0bc8cf29e 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -252,6 +252,13 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN : ((T)1 << (sizeof(T)*8-1)) \ ) +#if ENABLE_PLATFORM_MINGW32 && \ + (!defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO) +#define LL_FMT "I64" +#else +#define LL_FMT "ll" +#endif + /* Large file support */ /* Note that CONFIG_LFS=y forces bbox to be built with all common ops * (stat, lseek etc) mapped to "largefile" variants by libc. @@ -277,7 +284,7 @@ typedef unsigned long long uoff_t; # define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX) # define BB_STRTOOFF bb_strtoull # define STRTOOFF strtoull -# define OFF_FMT "ll" +# define OFF_FMT LL_FMT # endif #else /* CONFIG_LFS is off */ diff --git a/libbb/xatonum_template.c b/libbb/xatonum_template.c index e0471983c..0d5d35b47 100644 --- a/libbb/xatonum_template.c +++ b/libbb/xatonum_template.c @@ -67,7 +67,7 @@ unsigned type FAST_FUNC xstrtou(_range_sfx)(const char *numstr, int base, if (r >= lower && r <= upper) return r; range: - bb_error_msg_and_die("number %s is not in %llu..%llu range", + bb_error_msg_and_die("number %s is not in %"LL_FMT"u..%"LL_FMT"u range", numstr, (unsigned long long)lower, (unsigned long long)upper); inval: @@ -144,7 +144,8 @@ type FAST_FUNC xstrto(_range_sfx)(const char *numstr, int base, } if (r < lower || r > upper) { - bb_error_msg_and_die("number %s is not in %lld..%lld range", + bb_error_msg_and_die("number %s is not in " + "%"LL_FMT"d..%"LL_FMT"d range", numstr, (long long)lower, (long long)upper); } diff --git a/miscutils/dc.c b/miscutils/dc.c index 7986fef5f..6b8364dd9 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -56,7 +56,7 @@ typedef unsigned long data_t; #define DATA_FMT "l" #else typedef unsigned long long data_t; -#define DATA_FMT "ll" +#define DATA_FMT LL_FMT #endif diff --git a/procps/iostat.c b/procps/iostat.c index c290c594b..2db343f69 100644 --- a/procps/iostat.c +++ b/procps/iostat.c @@ -29,7 +29,7 @@ #if 1 typedef unsigned long long cputime_t; typedef long long icputime_t; -# define FMT_DATA "ll" +# define FMT_DATA LL_FMT # define CPUTIME_MAX (~0ULL) #else typedef unsigned long cputime_t; diff --git a/procps/mpstat.c b/procps/mpstat.c index 6028903fa..8a79fd8ba 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -49,7 +49,7 @@ #if 1 typedef unsigned long long data_t; typedef long long idata_t; -#define FMT_DATA "ll" +#define FMT_DATA LL_FMT #define DATA_MAX ULLONG_MAX #else typedef unsigned long data_t; diff --git a/shell/math.h b/shell/math.h index 32e1ffe35..90eb49144 100644 --- a/shell/math.h +++ b/shell/math.h @@ -65,7 +65,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN #if ENABLE_FEATURE_SH_MATH_64 typedef long long arith_t; -#define ARITH_FMT "%lld" +#define ARITH_FMT "%"LL_FMT"d" #define strto_arith_t strtoull #else typedef long arith_t; -- cgit v1.2.3-55-g6feb