aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-28 21:14:23 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-28 21:14:23 +0100
commit9f1f3f959d3411c200afb5a1df4fffa9d87df616 (patch)
treef9fb6a8678579bebee4dc121d63f75c3d0c224fb
parent587a56c4fb08ceac99752a6208d5585ba1f17957 (diff)
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 <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/util/util.h3
-rw-r--r--lib/fstree/fstree_from_file.c14
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 <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
@@ -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 '<c|b> major minor'\n",
+ fprintf(stderr, "%s: " PRI_SZ ": "
+ "expected '<c|b> 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: <type> <path> <mode> <uid> <gid> [<extra>]\n",
stderr);
return -1;