[patch] WORDSIZE dependant printf length modifiers
Bernhard Fischer
rep.nop at aon.at
Wed Apr 5 11:08:31 UTC 2006
On Wed, Apr 05, 2006 at 10:30:15AM +0200, Bernhard Fischer wrote:
>Hi,
>
>single-applet buildlog for trunk, r14744
The attached proposed patch would use the proper length modifiers
depending on the wordsize.
The reasoning behind this is that uintmax_t depends on the wordsize.
Comments? Ok for trunk?
>Tue Apr 4 14:47:06 CEST 2006
>--
># CONFIG_STAT=y: CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
>coreutils/stat.c: In function 'do_stat':
>coreutils/stat.c:485: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'long long unsigned int'
>coreutils/stat.c:485: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'long long unsigned int'
>coreutils/stat.c:485: warning: format '%lx' expects type 'long unsigned int', but argument 8 has type '__dev_t'
>coreutils/stat.c:485: warning: format '%lu' expects type 'long unsigned int', but argument 9 has type 'long long unsigned int'
>coreutils/stat.c:512: warning: format '%-10lu' expects type 'long unsigned int', but argument 2 has type 'long long unsigned int'
>coreutils/stat.c:512: warning: format '%-10lu' expects type 'long unsigned int', but argument 3 has type 'long long unsigned int'
>coreutils/stat.c:512: warning: format '%lx' expects type 'long unsigned int', but argument 6 has type '__dev_t'
>coreutils/stat.c:512: warning: format '%lu' expects type 'long unsigned int', but argument 7 has type '__dev_t'
>coreutils/stat.c:512: warning: format '%-10lu' expects type 'long unsigned int', but argument 8 has type 'long long unsigned int'
-------------- next part --------------
Index: coreutils/stat.c
===================================================================
--- coreutils/stat.c (revision 14753)
+++ coreutils/stat.c (working copy)
@@ -466,7 +466,7 @@
print_it(format, filename, print_stat, &statbuf);
#else
if (flags & OPT_TERSE) {
- printf("%s %lu %lu %lx %lu %lu %lx %lu %lu %lx %lx %lu %lu %lu %lu\n",
+ printf("%s %"FMTu64" %"FMTu64" %lx %lu %lu %"FMTx64" %"FMTu64" %lu %lx %lx %lu %lu %lu %lu\n",
filename,
(uintmax_t) (statbuf.st_size),
(uintmax_t) statbuf.st_blocks,
@@ -500,8 +500,8 @@
else
printf(" File: \"%s\"\n", filename);
- printf(" Size: %-10lu\tBlocks: %-10lu IO Block: %-6lu %s\n"
- "Device: %lxh/%lud\tInode: %-10lu Links: %-5lu",
+ printf(" Size: %-10"FMTu64"\tBlocks: %-10"FMTu64" IO Block: %-6lu %s\n"
+ "Device: %"FMTx64"h/%"FMTu64"d\tInode: %-10"FMTu64" Links: %-5lu",
(uintmax_t) (statbuf.st_size),
(uintmax_t) statbuf.st_blocks,
(unsigned long int) statbuf.st_blksize,
Index: include/platform.h
===================================================================
--- include/platform.h (revision 14753)
+++ include/platform.h (working copy)
@@ -95,6 +95,22 @@
# define BB_LITTLE_ENDIAN 1
#endif
+/* ---- Wordsize -------------------------------------------- */
+#ifndef __WORDSIZE
+#include <bits/wordsize>
+#endif
+
+#if __WORDSIZE == 64
+# define __FMT64_PFX "l"
+#elif __WORDSIZE == 32
+# define __FMT64_PFX "ll"
+#else
+#error unsupported WORDSIZE
+#endif
+/* printf length modifier */
+#define FMTu64 __FMT64_PFX"u"
+#define FMTx64 __FMT64_PFX"x"
+
/* ---- Networking ------------------------------------------ */
#ifndef __APPLE__
# include <arpa/inet.h>
More information about the busybox
mailing list