From 9f1f3f959d3411c200afb5a1df4fffa9d87df616 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 28 Oct 2019 21:14:23 +0100 Subject: Add macro for printf format specifier for size_t The MSVC runtime is a wierdo C89 platform with some cherry picked features from C99 (which does not include the "%zu" format specifier). This commit adds a macro with a size dependend format specifier to be used instead. Signed-off-by: David Oberhollenzer --- include/util/util.h | 3 +++ lib/fstree/fstree_from_file.c | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/util/util.h b/include/util/util.h index 881b59c..a08c7ee 100644 --- a/include/util/util.h +++ b/include/util/util.h @@ -30,12 +30,15 @@ #if SIZEOF_SIZE_T <= SIZEOF_INT #define SZ_ADD_OV UI_ADD_OV #define SZ_MUL_OV UI_MUL_OV +#define PRI_SZ "%u" #elif SIZEOF_SIZE_T == SIZEOF_LONG #define SZ_ADD_OV UL_ADD_OV #define SZ_MUL_OV UL_MUL_OV +#define PRI_SZ "%lu" #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG #define SZ_ADD_OV ULL_ADD_OV #define SZ_MUL_OV ULL_MUL_OV +#define PRI_SZ "%llu" #else #error Cannot determine maximum value of size_t #endif diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c index eee7d5a..825a2e2 100644 --- a/lib/fstree/fstree_from_file.c +++ b/lib/fstree/fstree_from_file.c @@ -9,7 +9,6 @@ #include "fstree.h" #include "util/util.h" -#include #include #include #include @@ -20,7 +19,7 @@ static int add_generic(fstree_t *fs, const char *filename, size_t line_num, const char *path, struct stat *sb, const char *extra) { if (fstree_add_generic(fs, path, sb, extra) == NULL) { - fprintf(stderr, "%s: %zu: %s: %s\n", + fprintf(stderr, "%s: " PRI_SZ ": %s: %s\n", filename, line_num, path, strerror(errno)); return -1; } @@ -35,7 +34,8 @@ static int add_device(fstree_t *fs, const char *filename, size_t line_num, char c; if (sscanf(extra, "%c %u %u", &c, &maj, &min) != 3) { - fprintf(stderr, "%s: %zu: expected ' major minor'\n", + fprintf(stderr, "%s: " PRI_SZ ": " + "expected ' major minor'\n", filename, line_num); return -1; } @@ -45,7 +45,7 @@ static int add_device(fstree_t *fs, const char *filename, size_t line_num, } else if (c == 'b' || c == 'B') { sb->st_mode |= S_IFBLK; } else { - fprintf(stderr, "%s: %zu: unknown device type '%c'\n", + fprintf(stderr, "%s: " PRI_SZ ": unknown device type '%c'\n", filename, line_num, c); return -1; } @@ -240,11 +240,11 @@ static int handle_line(fstree_t *fs, const char *filename, } } - fprintf(stderr, "%s: %zu: unknown entry type '%s'.\n", filename, + fprintf(stderr, "%s: " PRI_SZ ": unknown entry type '%s'.\n", filename, line_num, keyword); return -1; fail_no_extra: - fprintf(stderr, "%s: %zu: missing argument for %s.\n", + fprintf(stderr, "%s: " PRI_SZ ": missing argument for %s.\n", filename, line_num, keyword); return -1; fail_uid_gid: @@ -260,7 +260,7 @@ fail_ent: msg = "error in entry description"; goto out_desc; out_desc: - fprintf(stderr, "%s: %zu: %s.\n", filename, line_num, msg); + fprintf(stderr, "%s: " PRI_SZ ": %s.\n", filename, line_num, msg); fputs("expected: []\n", stderr); return -1; -- cgit v1.2.3