aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-04-17 17:59:21 +0200
committerMarco Paland <marco@paland.com>2018-04-17 17:59:21 +0200
commitca6e7e5291986b95e0fad98a0a9018c8c8ce1fe1 (patch)
treea672a225e5c81fa611972257ffe51b3d13d85cd0
parent896b2ce07b6ea0660408fc5698026c8a3af3aa3d (diff)
parent281e44d53b4506b3e0e737f93af48d0c1ea5ac3e (diff)
downloadprintf-ca6e7e5291986b95e0fad98a0a9018c8c8ce1fe1.tar.gz
printf-ca6e7e5291986b95e0fad98a0a9018c8c8ce1fe1.tar.bz2
printf-ca6e7e5291986b95e0fad98a0a9018c8c8ce1fe1.zip
Merge branch 'size_t_specifier_support'
-rw-r--r--README.md1
-rw-r--r--printf.c4
-rw-r--r--test/test_suite.cpp17
3 files changed, 21 insertions, 1 deletions
diff --git a/README.md b/README.md
index 7f91d8d..753a1e1 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,7 @@ The length sub-specifier modifies the length of the data type.
| (none) | int | unsigned int |
| l | long int | unsigned long int |
| ll | long long int | unsigned long long int |
+| z | size_t int | unsigned size_t int |
## Compiler switches/defines
diff --git a/printf.c b/printf.c
index a65f418..e5e3a36 100644
--- a/printf.c
+++ b/printf.c
@@ -425,6 +425,10 @@ static size_t _vsnprintf(char* buffer, size_t buffer_len, const char* format, va
flags |= FLAGS_LONG_LONG;
format++;
}
+ if (*format == 'z') {
+ flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
+ format++;
+ }
// evaluate specifier
switch (*format) {
diff --git a/test/test_suite.cpp b/test/test_suite.cpp
index e241195..0a51e09 100644
--- a/test/test_suite.cpp
+++ b/test/test_suite.cpp
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com)
-// 2017, PALANDesign Hannover, Germany
+// 2017-2018, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
@@ -923,6 +923,21 @@ TEST_CASE("types", "[]" ) {
test::sprintf(buffer, "%llu", 18446744073709551615LLU);
REQUIRE(!strcmp(buffer, "18446744073709551615"));
+ test::sprintf(buffer, "%zu", 2147483647UL);
+ REQUIRE(!strcmp(buffer, "2147483647"));
+
+ test::sprintf(buffer, "%zd", 2147483647UL);
+ REQUIRE(!strcmp(buffer, "2147483647"));
+
+ if (sizeof(size_t) == sizeof(long)) {
+ test::sprintf(buffer, "%zi", -2147483647L);
+ REQUIRE(!strcmp(buffer, "-2147483647"));
+ }
+ else {
+ test::sprintf(buffer, "%zi", -2147483647LL);
+ REQUIRE(!strcmp(buffer, "-2147483647"));
+ }
+
test::sprintf(buffer, "%b", 60000);
REQUIRE(!strcmp(buffer, "1110101001100000"));