]> www.infradead.org Git - mtd-utils.git/commitdiff
mtd-utils: Fix format specifier definitions for off_t and loff_t.
authorTorsten Fleischer <torfl@t-online.de>
Sat, 11 Feb 2017 16:43:31 +0000 (17:43 +0100)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Mon, 20 Feb 2017 12:12:47 +0000 (13:12 +0100)
On 32bit systems (e.g. ARM) the size of off_t can be 4 byte and the size of loff_t 8 byte.

This causes compiler warnings like the following:

flash_erase.c: In function 'show_progress':
flash_erase.c:56:22: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 3 has type 'off_t {aka long int}' [-Wformat=]
  bareverbose(!quiet, "\rErasing %d Kibyte @ %"PRIxoff_t" -- %2i %% complete ",

and an output like this:

~# flash_erase /dev/mtd2 0 1
Erasing 64 Kibyte @ 6400000000 -- 0 % complete

~#

Since the size of off_t and loff_t can differ from each other, the
printf format specifier should be determined separately for both.
Further the format specifiers should be based directly on the size of the
particular data type.

Signed-off-by: Torsten Fleischer <torfl6749@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
configure.ac
include/common.h
tests/mtd-tests/nandpagetest.c

index a5fc3a52e0f74b2a64437cc6a30f3cbdbde724c6..fbef15ce2dfe2d610bba2da85e0096b2534de6d7 100644 (file)
@@ -149,7 +149,7 @@ AM_COND_IF([WITHOUT_LZO], [], [
        test "${have_lzo}" != "yes" && AC_MSG_ERROR([lzo missing])
 ])
 
-AC_CHECK_SIZEOF([long])
+AC_CHECK_SIZEOF([off_t])
 
 AC_CHECK_SIZEOF([loff_t])
 
index 2812f49ad39b5187bf9e94aa4acb7d937eb12862..d0c706d6f23a9ee2783facc8905c4c4dc3353705 100644 (file)
@@ -70,17 +70,21 @@ extern "C" {
 #endif
 
 /* define a print format specifier for off_t */
-#ifdef __USE_FILE_OFFSET64
+#if (SIZEOF_OFF_T >= 8)
 #define PRIxoff_t PRIx64
 #define PRIdoff_t PRId64
 #else
-#if (SIZEOF_LONG == SIZEOF_LOFF_T)
 #define PRIxoff_t "l"PRIx32
 #define PRIdoff_t "l"PRId32
-#else
-#define PRIxoff_t "ll"PRIx32
-#define PRIdoff_t "ll"PRId32
 #endif
+
+/* define a print format specifier for loff_t */
+#if (SIZEOF_LOFF_T >= 8)
+#define PRIxloff_t PRIx64
+#define PRIdloff_t PRId64
+#else
+#define PRIxloff_t "l"PRIx32
+#define PRIdloff_t "l"PRId32
 #endif
 
 /* Verbose messages */
index faf5fe331e384242fb625e7ec23de7d271636803..4145ef79231291ae74841b7306606776f4724a4a 100644 (file)
@@ -230,7 +230,7 @@ static int verify_eraseblock(int ebnum)
                        return err;
 
                if (lseek(fd, addr, SEEK_SET) != addr) {
-                       fprintf(stderr, "cannot seek mtd%d to offset %"PRIdoff_t,
+                       fprintf(stderr, "cannot seek mtd%d to offset %"PRIdloff_t,
                                        mtd.mtd_num, addr);
                        return -1;
                }