aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2014-07-25 14:31:23 +0100
committerAndreas Schneider <asn@cryptomilk.org>2014-07-28 09:19:03 +0200
commitd07cff1b13af4fde05d2fa081c7f33c115ecf841 (patch)
tree3e45a62c8e510ddde6e543ea4d440abc9d34045c
parent8642ef21b07e025a9aa117867811a725e2fb597e (diff)
downloadcmocka-d07cff1b13af4fde05d2fa081c7f33c115ecf841.tar.gz
cmocka-d07cff1b13af4fde05d2fa081c7f33c115ecf841.tar.xz
cmocka-d07cff1b13af4fde05d2fa081c7f33c115ecf841.zip
cmocka: use ISO C99 PRIu64 over LargestIntegralTypePrintfUnsignedFormat
With commit commit 8642ef21b07(cmocka: introduce LargestIntegralTypePrintfUnsignedFormat modifier) we introduces this superfluous macro in order to work around the differences when printing 64bit unsigned integer values. Rather than reinventing the wheel use the C99's PRIu64 and fall back locally to their platform/compiler specific counterparts if the inttypes.h header does not exist. Thanks to scythe from the #cmocka channel for pointing out. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/cmocka.h9
-rw-r--r--src/cmocka.c31
2 files changed, 18 insertions, 22 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index 5814805..a60b2a5 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -85,15 +85,6 @@ int __stdcall IsDebuggerPresent();
#endif /* _WIN32 */
#endif /* LargestIntegralTypePrintfFormat */
-/* Printf format used to display LargestIntegralType as unsigned. */
-#ifndef LargestIntegralTypePrintfUnsignedFormat
-#ifdef _WIN32
-#define LargestIntegralTypePrintfUnsignedFormat "%I64u"
-#else
-#define LargestIntegralTypePrintfUnsignedFormat "%llu"
-#endif /* _WIN32 */
-#endif /* LargestIntegralTypePrintfFormat */
-
/* Perform an unsigned cast to LargestIntegralType. */
#define cast_to_largest_integral_type(value) \
((LargestIntegralType)((size_t)(value)))
diff --git a/src/cmocka.c b/src/cmocka.c
index ef6ee8a..69f792d 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -21,6 +21,10 @@
#include <malloc.h>
#endif
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@@ -43,12 +47,20 @@ WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
#define PRIdS "Id"
#endif
+#ifndef PRIu64
+#define PRIu64 "I64u"
+#endif
+
#else /* _WIN32 */
#ifndef PRIdS
#define PRIdS "zd"
#endif
+#ifndef PRIu64
+#define PRIu64 "llu"
+#endif
+
#include <signal.h>
#endif /* _WIN32 */
@@ -819,10 +831,10 @@ static int value_in_set_display_error(
if (succeeded) {
return 1;
}
- print_error(LargestIntegralTypePrintfUnsignedFormat
- "is %sin the set (", value, invert ? "" : "not ");
+ print_error("%" PRIu64 " is %sin the set (", value,
+ invert ? "" : "not ");
for (i = 0; i < size_of_set; i++) {
- print_error(LargestIntegralTypePrintfUnsignedFormat ", ", set[i]);
+ print_error("%" PRIu64 ", ", set[i]);
}
print_error(")\n");
}
@@ -841,10 +853,7 @@ static int integer_in_range_display_error(
if (value >= range_min && value <= range_max) {
return 1;
}
- print_error(LargestIntegralTypePrintfUnsignedFormat
- " is not within the range "
- LargestIntegralTypePrintfUnsignedFormat "-"
- LargestIntegralTypePrintfUnsignedFormat "\n",
+ print_error("%" PRIu64 " is not within the range %" PRIu64 "-%" PRIu64 "\n",
value, range_min, range_max);
return 0;
}
@@ -861,10 +870,7 @@ static int integer_not_in_range_display_error(
if (value < range_min || value > range_max) {
return 1;
}
- print_error(LargestIntegralTypePrintfUnsignedFormat
- " is within the range "
- LargestIntegralTypePrintfUnsignedFormat "-"
- LargestIntegralTypePrintfUnsignedFormat "\n",
+ print_error("%" PRIu64 " is within the range %" PRIu64 "-%" PRIu64 "\n",
value, range_min, range_max);
return 0;
}
@@ -1341,8 +1347,7 @@ void _assert_return_code(const LargestIntegralType result,
if (result > valmax - 1) {
if (error > 0) {
- print_error("%s < 0, errno("
- LargestIntegralTypePrintfUnsignedFormat "): %s\n",
+ print_error("%s < 0, errno(%" PRIu64 "): %s\n",
expression, error, strerror(error));
} else {
print_error("%s < 0\n", expression);