From fcff65b6d866f780d32d9328b6ae1f29622caea4 Mon Sep 17 00:00:00 2001
From: Martine Lenders <mail@martine-lenders.eu>
Date: Tue, 8 Nov 2016 17:10:07 +0100
Subject: [PATCH] od: quick-fix for newlib-nano

---
 sys/include/od.h         | 7 ++++++-
 sys/od/od.c              | 4 ++++
 tests/od/main.c          | 2 ++
 tests/od/tests/01-run.py | 3 +++
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/sys/include/od.h b/sys/include/od.h
index e15bb51a6e..99d2fb00c1 100644
--- a/sys/include/od.h
+++ b/sys/include/od.h
@@ -114,7 +114,12 @@ extern "C" {
 #define OD_FLAGS_LENGTH_1       (0x0010)    /**< 1 byte */
 #define OD_FLAGS_LENGTH_2       (0x0020)    /**< 2 byte */
 #define OD_FLAGS_LENGTH_4       (0x0000)    /**< 4 byte and default */
-#define OD_FLAGS_LENGTH_8       (0x0080)    /**< 8 byte */
+/**
+ * @brief   8 byte
+ *
+ * @warning not working with newlib-nano
+ */
+#define OD_FLAGS_LENGTH_8       (0x0080)
 #define OD_FLAGS_LENGTH_CHAR    (OD_FLAGS_LENGTH_1)    /**< alias for OD_FLAGS_LENGTH_1 */
 #define OD_FLAGS_LENGTH_SHORT   (0x0002)    /**< sizeof(short) byte */
 #define OD_FLAGS_LENGTH_LONG    (0x0004)    /**< sizeof(long) byte */
diff --git a/sys/od/od.c b/sys/od/od.c
index d4d70d17e2..c5cb933be0 100644
--- a/sys/od/od.c
+++ b/sys/od/od.c
@@ -303,12 +303,16 @@ static void _print_date(const void *data, size_t offset, char *format, uint8_t l
             break;
 
         case 8:
+#ifndef MODULE_NEWLIB
             if (flags & OD_FLAGS_BYTES_INT) {
                 printf(format, ((int64_t *)data)[offset]);
             }
             else {
                 printf(format, ((uint64_t *)data)[offset]);
             }
+#else
+            printf("%s", format);
+#endif
 
             break;
 
diff --git a/tests/od/main.c b/tests/od/main.c
index 08a876e5c7..6d7f5093f9 100644
--- a/tests/od/main.c
+++ b/tests/od/main.c
@@ -143,6 +143,7 @@ int main(void)
             OD_FLAGS_BYTES_HEX | OD_FLAGS_LENGTH_4));
 
     /* Test different 8-byte-wise byte formats */
+#ifndef MODULE_NEWLIB
     CALL(od(long_str, sizeof(long_str), OD_WIDTH_DEFAULT,
             OD_FLAGS_BYTES_INT | OD_FLAGS_LENGTH_8));
     CALL(od(long_str, sizeof(long_str), OD_WIDTH_DEFAULT,
@@ -151,6 +152,7 @@ int main(void)
             OD_FLAGS_BYTES_UINT | OD_FLAGS_LENGTH_8));
     CALL(od(long_str, sizeof(long_str), OD_WIDTH_DEFAULT,
             OD_FLAGS_BYTES_HEX | OD_FLAGS_LENGTH_8));
+#endif
 
     /* Test different char-wise byte formats */
     CALL(od(long_str, sizeof(long_str), OD_WIDTH_DEFAULT,
diff --git a/tests/od/tests/01-run.py b/tests/od/tests/01-run.py
index a7d9afa8e1..31e5c59bb0 100755
--- a/tests/od/tests/01-run.py
+++ b/tests/od/tests/01-run.py
@@ -13,6 +13,9 @@ sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
 import testrunner
 
 def testfunc(child):
+    # check if running with newlib
+    print("ATTENTION: This script is currently not suitable for non-native platforms")
+
     # test data width vs. output width discrepency
     child.expect_exact(r'od(short_str, sizeof(short_str), OD_WIDTH_DEFAULT, 0)')
     child.expect_exact(r'000000000 000000041101')
-- 
GitLab