You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2020/07/29 08:02:32 UTC
[mynewt-core] branch master updated (3e34962 -> 40589e6)
This is an automated email from the ASF dual-hosted git repository.
janc pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.
from 3e34962 hw/mcu/dialog: Fix pd_com handling in hal_uart
new c1f0300 libc/baselibc: Remove own version of inttypes.h
new 40589e6 libs/baselibc: Add support for printf 'h' modifier
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
libc/baselibc/include/inttypes.h | 237 --------------------
libc/baselibc/include/strntoimax.h | 22 ++
{fs/fcb => libc/baselibc}/selftest/pkg.yml | 8 +-
.../baselibc/selftest/src/baselibc_test.c | 13 +-
.../selftest/src/testcases/tinyprintf_test.c | 240 +++++++++++++++++++++
libc/baselibc/src/strntoimax.c | 2 +-
libc/baselibc/src/strntoumax.c | 2 +-
libc/baselibc/src/templates/atox.c.template | 2 +-
libc/baselibc/src/templates/strtox.c.template | 2 +-
libc/baselibc/src/tinyprintf.c | 25 ++-
libc/baselibc/src/vsscanf.c | 2 +-
11 files changed, 300 insertions(+), 255 deletions(-)
delete mode 100644 libc/baselibc/include/inttypes.h
create mode 100644 libc/baselibc/include/strntoimax.h
copy {fs/fcb => libc/baselibc}/selftest/pkg.yml (91%)
mode change 100644 => 100755
copy net/oic/selftest/src/test_oic.c => libc/baselibc/selftest/src/baselibc_test.c (85%)
mode change 100644 => 100755
create mode 100755 libc/baselibc/selftest/src/testcases/tinyprintf_test.c
[mynewt-core] 01/02: libc/baselibc: Remove own version of inttypes.h
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit c1f0300413fc981741d37d655654de1dbca5d4df
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Mon May 18 14:55:23 2020 +0200
libc/baselibc: Remove own version of inttypes.h
We should be using version provided by compiler for proper string
modifiers definitions. Mynewt extensions were moved to separate header.
---
libc/baselibc/include/inttypes.h | 237 --------------------------
libc/baselibc/include/strntoimax.h | 22 +++
libc/baselibc/src/strntoimax.c | 2 +-
libc/baselibc/src/strntoumax.c | 2 +-
libc/baselibc/src/templates/atox.c.template | 2 +-
libc/baselibc/src/templates/strtox.c.template | 2 +-
libc/baselibc/src/vsscanf.c | 2 +-
7 files changed, 27 insertions(+), 242 deletions(-)
diff --git a/libc/baselibc/include/inttypes.h b/libc/baselibc/include/inttypes.h
deleted file mode 100644
index ce4159a..0000000
--- a/libc/baselibc/include/inttypes.h
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * inttypes.h
- */
-
-#ifndef _INTTYPES_H
-#define _INTTYPES_H
-
-#include <klibc/extern.h>
-#include <stdint.h>
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static __inline__ intmax_t imaxabs(intmax_t __n)
-{
- return (__n < (intmax_t) 0) ? -__n : __n;
-}
-
-__extern intmax_t strtoimax(const char *, char **, int);
-__extern uintmax_t strtoumax(const char *, char **, int);
-
-/* extensions */
-__extern intmax_t strntoimax(const char *, char **, int, size_t);
-__extern uintmax_t strntoumax(const char *, char **, int, size_t);
-
-#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
-
-#define __PRI64_RANK "ll"
-#define __PRI32_RANK "l"
-
-#define PRId8 "d"
-#define PRId16 "d"
-#define PRId32 "d"
-#define PRId64 __PRI64_RANK "d"
-
-#define PRIdLEAST8 "d"
-#define PRIdLEAST16 "d"
-#define PRIdLEAST32 "d"
-#define PRIdLEAST64 __PRI64_RANK "d"
-
-#define PRIdFAST8 "d"
-#define PRIdFAST16 __PRIFAST_RANK "d"
-#define PRIdFAST32 __PRIFAST_RANK "d"
-#define PRIdFAST64 __PRI64_RANK "d"
-
-#define PRIdMAX __PRI64_RANK "d"
-#define PRIdPTR __PRIPTR_RANK "d"
-
-#define PRIi8 "i"
-#define PRIi16 "i"
-#define PRIi32 "i"
-#define PRIi64 __PRI64_RANK "i"
-
-#define PRIiLEAST8 "i"
-#define PRIiLEAST16 "i"
-#define PRIiLEAST32 "i"
-#define PRIiLEAST64 __PRI64_RANK "i"
-
-#define PRIiFAST8 "i"
-#define PRIiFAST16 __PRIFAST_RANK "i"
-#define PRIiFAST32 __PRIFAST_RANK "i"
-#define PRIiFAST64 __PRI64_RANK "i"
-
-#define PRIiMAX __PRI64_RANK "i"
-#define PRIiPTR __PRIPTR_RANK "i"
-
-#define PRIo8 "o"
-#define PRIo16 "o"
-#define PRIo32 "o"
-#define PRIo64 __PRI64_RANK "o"
-
-#define PRIoLEAST8 "o"
-#define PRIoLEAST16 "o"
-#define PRIoLEAST32 "o"
-#define PRIoLEAST64 __PRI64_RANK "o"
-
-#define PRIoFAST8 "o"
-#define PRIoFAST16 __PRIFAST_RANK "o"
-#define PRIoFAST32 __PRIFAST_RANK "o"
-#define PRIoFAST64 __PRI64_RANK "o"
-
-#define PRIoMAX __PRI64_RANK "o"
-#define PRIoPTR __PRIPTR_RANK "o"
-
-#define PRIu8 "u"
-#define PRIu16 "u"
-#define PRIu32 "u"
-#define PRIu64 __PRI64_RANK "u"
-
-#define PRIuLEAST8 "u"
-#define PRIuLEAST16 "u"
-#define PRIuLEAST32 "u"
-#define PRIuLEAST64 __PRI64_RANK "u"
-
-#define PRIuFAST8 "u"
-#define PRIuFAST16 __PRIFAST_RANK "u"
-#define PRIuFAST32 __PRIFAST_RANK "u"
-#define PRIuFAST64 __PRI64_RANK "u"
-
-#define PRIuMAX __PRI64_RANK "u"
-#define PRIuPTR __PRIPTR_RANK "u"
-
-#define PRIx8 "x"
-#define PRIx16 "x"
-#define PRIx32 __PRI32_RANK "x"
-#define PRIx64 __PRI64_RANK "x"
-
-#define PRIxLEAST8 "x"
-#define PRIxLEAST16 "x"
-#define PRIxLEAST32 "x"
-#define PRIxLEAST64 __PRI64_RANK "x"
-
-#define PRIxFAST8 "x"
-#define PRIxFAST16 __PRIFAST_RANK "x"
-#define PRIxFAST32 __PRIFAST_RANK "x"
-#define PRIxFAST64 __PRI64_RANK "x"
-
-#define PRIxMAX __PRI64_RANK "x"
-#define PRIxPTR __PRIPTR_RANK "x"
-
-#define PRIX8 "X"
-#define PRIX16 "X"
-#define PRIX32 __PRI32_RANK "X"
-#define PRIX64 __PRI64_RANK "X"
-
-#define PRIXLEAST8 "X"
-#define PRIXLEAST16 "X"
-#define PRIXLEAST32 "X"
-#define PRIXLEAST64 __PRI64_RANK "X"
-
-#define PRIXFAST8 "X"
-#define PRIXFAST16 __PRIFAST_RANK "X"
-#define PRIXFAST32 __PRIFAST_RANK "X"
-#define PRIXFAST64 __PRI64_RANK "X"
-
-#define PRIXMAX __PRI64_RANK "X"
-#define PRIXPTR __PRIPTR_RANK "X"
-
-#define SCNd8 "hhd"
-#define SCNd16 "hd"
-#define SCNd32 "d"
-#define SCNd64 __PRI64_RANK "d"
-
-#define SCNdLEAST8 "hhd"
-#define SCNdLEAST16 "hd"
-#define SCNdLEAST32 "d"
-#define SCNdLEAST64 __PRI64_RANK "d"
-
-#define SCNdFAST8 "hhd"
-#define SCNdFAST16 __PRIFAST_RANK "d"
-#define SCNdFAST32 __PRIFAST_RANK "d"
-#define SCNdFAST64 __PRI64_RANK "d"
-
-#define SCNdMAX __PRI64_RANK "d"
-#define SCNdPTR __PRIPTR_RANK "d"
-
-#define SCNi8 "hhi"
-#define SCNi16 "hi"
-#define SCNi32 "i"
-#define SCNi64 __PRI64_RANK "i"
-
-#define SCNiLEAST8 "hhi"
-#define SCNiLEAST16 "hi"
-#define SCNiLEAST32 "i"
-#define SCNiLEAST64 __PRI64_RANK "i"
-
-#define SCNiFAST8 "hhi"
-#define SCNiFAST16 __PRIFAST_RANK "i"
-#define SCNiFAST32 __PRIFAST_RANK "i"
-#define SCNiFAST64 __PRI64_RANK "i"
-
-#define SCNiMAX __PRI64_RANK "i"
-#define SCNiPTR __PRIPTR_RANK "i"
-
-#define SCNo8 "hho"
-#define SCNo16 "ho"
-#define SCNo32 "o"
-#define SCNo64 __PRI64_RANK "o"
-
-#define SCNoLEAST8 "hho"
-#define SCNoLEAST16 "ho"
-#define SCNoLEAST32 "o"
-#define SCNoLEAST64 __PRI64_RANK "o"
-
-#define SCNoFAST8 "hho"
-#define SCNoFAST16 __PRIFAST_RANK "o"
-#define SCNoFAST32 __PRIFAST_RANK "o"
-#define SCNoFAST64 __PRI64_RANK "o"
-
-#define SCNoMAX __PRI64_RANK "o"
-#define SCNoPTR __PRIPTR_RANK "o"
-
-#define SCNu8 "hhu"
-#define SCNu16 "hu"
-#define SCNu32 "u"
-#define SCNu64 __PRI64_RANK "u"
-
-#define SCNuLEAST8 "hhu"
-#define SCNuLEAST16 "hu"
-#define SCNuLEAST32 "u"
-#define SCNuLEAST64 __PRI64_RANK "u"
-
-#define SCNuFAST8 "hhu"
-#define SCNuFAST16 __PRIFAST_RANK "u"
-#define SCNuFAST32 __PRIFAST_RANK "u"
-#define SCNuFAST64 __PRI64_RANK "u"
-
-#define SCNuMAX __PRI64_RANK "u"
-#define SCNuPTR __PRIPTR_RANK "u"
-
-#define SCNx8 "hhx"
-#define SCNx16 "hx"
-#define SCNx32 "x"
-#define SCNx64 __PRI64_RANK "x"
-
-#define SCNxLEAST8 "hhx"
-#define SCNxLEAST16 "hx"
-#define SCNxLEAST32 "x"
-#define SCNxLEAST64 __PRI64_RANK "x"
-
-#define SCNxFAST8 "hhx"
-#define SCNxFAST16 __PRIFAST_RANK "x"
-#define SCNxFAST32 __PRIFAST_RANK "x"
-#define SCNxFAST64 __PRI64_RANK "x"
-
-#define SCNxMAX __PRI64_RANK "x"
-#define SCNxPTR __PRIPTR_RANK "x"
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _INTTYPES_H */
diff --git a/libc/baselibc/include/strntoimax.h b/libc/baselibc/include/strntoimax.h
new file mode 100644
index 0000000..c7a3dab
--- /dev/null
+++ b/libc/baselibc/include/strntoimax.h
@@ -0,0 +1,22 @@
+/*
+ * strntoimax.h
+ */
+
+#ifndef _STRNTOIMAX_H
+#define _STRNTOIMAX_H
+
+#include <klibc/extern.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+__extern intmax_t strntoimax(const char *, char **, int, size_t);
+__extern uintmax_t strntoumax(const char *, char **, int, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _STRNTOIMAX_H */
diff --git a/libc/baselibc/src/strntoimax.c b/libc/baselibc/src/strntoimax.c
index 179d9e5..43a15cf 100644
--- a/libc/baselibc/src/strntoimax.c
+++ b/libc/baselibc/src/strntoimax.c
@@ -5,7 +5,7 @@
*/
#include <stddef.h>
-#include <inttypes.h>
+#include <strntoimax.h>
intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
{
diff --git a/libc/baselibc/src/strntoumax.c b/libc/baselibc/src/strntoumax.c
index 56dddad..93ff9b7 100644
--- a/libc/baselibc/src/strntoumax.c
+++ b/libc/baselibc/src/strntoumax.c
@@ -7,7 +7,7 @@
#include <stddef.h>
#include <stdint.h>
#include <ctype.h>
-#include <inttypes.h>
+#include <strntoimax.h>
static inline int digitval(int ch)
{
diff --git a/libc/baselibc/src/templates/atox.c.template b/libc/baselibc/src/templates/atox.c.template
index c013bb4..c112a7c 100644
--- a/libc/baselibc/src/templates/atox.c.template
+++ b/libc/baselibc/src/templates/atox.c.template
@@ -4,9 +4,9 @@
* atoi(), atol(), atoll()
*/
-#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
+#include <strntoimax.h>
TYPE NAME(const char *nptr)
{
diff --git a/libc/baselibc/src/templates/strtox.c.template b/libc/baselibc/src/templates/strtox.c.template
index c22e7c7..9009d72 100644
--- a/libc/baselibc/src/templates/strtox.c.template
+++ b/libc/baselibc/src/templates/strtox.c.template
@@ -6,7 +6,7 @@
#include <stddef.h>
#include <stdlib.h>
-#include <inttypes.h>
+#include <strntoimax.h>
TYPE NAME(const char *nptr, char **endptr, int base)
{
diff --git a/libc/baselibc/src/vsscanf.c b/libc/baselibc/src/vsscanf.c
index 60eaca6..ddd3d7e 100644
--- a/libc/baselibc/src/vsscanf.c
+++ b/libc/baselibc/src/vsscanf.c
@@ -8,10 +8,10 @@
#include <ctype.h>
#include <stdarg.h>
#include <stddef.h>
-#include <inttypes.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
+#include <strntoimax.h>
#ifndef LONG_BIT
#define LONG_BIT (CHAR_BIT*sizeof(long))
[mynewt-core] 02/02: libs/baselibc: Add support for printf 'h'
modifier
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 40589e627914b26f441b3a24915e2337fd2d9221
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Tue Jul 28 15:45:09 2020 +0200
libs/baselibc: Add support for printf 'h' modifier
This also adds basic unit tests for this.
---
libc/baselibc/selftest/pkg.yml | 29 +++
libc/baselibc/selftest/src/baselibc_test.c | 37 ++++
.../selftest/src/testcases/tinyprintf_test.c | 240 +++++++++++++++++++++
libc/baselibc/src/tinyprintf.c | 25 ++-
4 files changed, 327 insertions(+), 4 deletions(-)
diff --git a/libc/baselibc/selftest/pkg.yml b/libc/baselibc/selftest/pkg.yml
new file mode 100755
index 0000000..2b6d1bf
--- /dev/null
+++ b/libc/baselibc/selftest/pkg.yml
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+pkg.name: libc/baselibc/selftest
+pkg.type: unittest
+pkg.description: "baselibc unit tests."
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "libc/baselibc"
+ - "@apache-mynewt-core/test/testutil"
+ - "@apache-mynewt-core/sys/console/stub"
+ - "@apache-mynewt-core/sys/log/stub"
diff --git a/libc/baselibc/selftest/src/baselibc_test.c b/libc/baselibc/selftest/src/baselibc_test.c
new file mode 100755
index 0000000..6fbb6c9
--- /dev/null
+++ b/libc/baselibc/selftest/src/baselibc_test.c
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <assert.h>
+#include <stddef.h>
+#include "os/mynewt.h"
+#include "testutil/testutil.h"
+
+TEST_CASE_DECL(tinyprintf_test)
+
+TEST_SUITE(baselibc_test_suite)
+{
+ tinyprintf_test();
+}
+
+int
+main(int argc, char **argv)
+{
+ baselibc_test_suite();
+
+ return tu_any_failed;
+}
diff --git a/libc/baselibc/selftest/src/testcases/tinyprintf_test.c b/libc/baselibc/selftest/src/testcases/tinyprintf_test.c
new file mode 100755
index 0000000..a9024c5
--- /dev/null
+++ b/libc/baselibc/selftest/src/testcases/tinyprintf_test.c
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <string.h>
+#include <stdio.h>
+#include "testutil/testutil.h"
+
+static const struct test_data {
+ const char *format;
+ long long number;
+ const char *result;
+} tests[] = {
+/* hex */
+ {
+ .format = "%hx",
+ .number = 0x2a,
+ .result = "2a",
+ },
+ {
+ .format = "%hx",
+ .number = 0xff,
+ .result = "ff",
+ },
+ {
+ .format = "%hx",
+ .number = 0xffff,
+ .result = "ffff",
+ },
+ {
+ .format = "%hx",
+ .number = 0x10000,
+ .result = "0",
+ },
+ {
+ .format = "%hx",
+ .number = 0x1ffff,
+ .result = "ffff",
+ },
+ {
+ .format = "%hhx",
+ .number = 0xff,
+ .result = "ff",
+ },
+ {
+ .format = "%hhx",
+ .number = 0x100,
+ .result = "0",
+ },
+ {
+ .format = "%hhx",
+ .number = 0x1ff,
+ .result = "ff",
+ },
+ {
+ .format = "%hhx",
+ .number = 0x1ff,
+ .result = "ff",
+ },
+/* HEX */
+ {
+ .format = "%hX",
+ .number = 0x2a,
+ .result = "2A",
+ },
+ {
+ .format = "%hX",
+ .number = 0xff,
+ .result = "FF",
+ },
+ {
+ .format = "%hX",
+ .number = 0xffff,
+ .result = "FFFF",
+ },
+ {
+ .format = "%hX",
+ .number = 0x10000,
+ .result = "0",
+ },
+ {
+ .format = "%hX",
+ .number = 0x1ffff,
+ .result = "FFFF",
+ },
+ {
+ .format = "%hhX",
+ .number = 0xff,
+ .result = "FF",
+ },
+ {
+ .format = "%hhX",
+ .number = 0x100,
+ .result = "0",
+ },
+ {
+ .format = "%hhX",
+ .number = 0x1ff,
+ .result = "FF",
+ },
+ {
+ .format = "%hhX",
+ .number = 0x1ff,
+ .result = "FF",
+ },
+/* unsigned decimal */
+ {
+ .format = "%hu",
+ .number = 42,
+ .result = "42",
+ },
+ {
+ .format = "%hu",
+ .number = 255,
+ .result = "255",
+ },
+ {
+ .format = "%hu",
+ .number = 65535,
+ .result = "65535",
+ },
+ {
+ .format = "%hu",
+ .number = 65536,
+ .result = "0",
+ },
+ {
+ .format = "%hu",
+ .number = 131071,
+ .result = "65535",
+ },
+ {
+ .format = "%hhu",
+ .number = 42,
+ .result = "42",
+ },
+ {
+ .format = "%hhu",
+ .number = 255,
+ .result = "255",
+ },
+ {
+ .format = "%hhu",
+ .number = 256,
+ .result = "0",
+ },
+ {
+ .format = "%hhu",
+ .number = 511,
+ .result = "255",
+ },
+/* signed decimal */
+ {
+ .format = "%hd",
+ .number = 42,
+ .result = "42",
+ },
+ {
+ .format = "%hd",
+ .number = -42,
+ .result = "-42",
+ },
+ {
+ .format = "%hd",
+ .number = 32767,
+ .result = "32767",
+ },
+ {
+ .format = "%hd",
+ .number = -32768,
+ .result = "-32768",
+ },
+ {
+ .format = "%hd",
+ .number = 32767 + 65536,
+ .result = "32767",
+ },
+ {
+ .format = "%hd",
+ .number = -32768 - 65536,
+ .result = "-32768",
+ },
+ {
+ .format = "%hhd",
+ .number = 42,
+ .result = "42",
+ },
+ {
+ .format = "%hhd",
+ .number = -42,
+ .result = "-42",
+ },
+ {
+ .format = "%hhd",
+ .number = 127,
+ .result = "127",
+ },
+ {
+ .format = "%hhd",
+ .number = -128,
+ .result = "-128",
+ },
+ {
+ .format = "%hhd",
+ .number = 127 + 256,
+ .result = "127",
+ },
+ {
+ .format = "%hhd",
+ .number = -127 - 256,
+ .result = "-127",
+ },
+};
+
+TEST_CASE_SELF(tinyprintf_test)
+{
+ char result[100];
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(tests); i++) {
+ memset(result, 0, sizeof(result));
+ snprintf(result, sizeof(result), tests[i].format, tests[i].number);
+
+ TEST_ASSERT(strcmp(result, tests[i].result) == 0);
+ }
+}
diff --git a/libc/baselibc/src/tinyprintf.c b/libc/baselibc/src/tinyprintf.c
index 5a15015..ca0a2de 100644
--- a/libc/baselibc/src/tinyprintf.c
+++ b/libc/baselibc/src/tinyprintf.c
@@ -71,10 +71,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
struct param {
unsigned char width; /**< field width */
char lz; /**< Leading zeros */
- char sign:1; /**< The sign to display (if any) */
- char alt:1; /**< alternate form */
- char uc:1; /**< Upper case (for base16 only) */
- char left:1; /**< Force text to left (padding on right) */
+ unsigned char sign:1; /**< The sign to display (if any) */
+ unsigned char alt:1; /**< alternate form */
+ unsigned char uc:1; /**< Upper case (for base16 only) */
+ unsigned char left:1; /**< Force text to left (padding on right) */
+ unsigned char hh:2; /**< Short value */
char base; /**< number base (e.g.: 8, 10, 16) */
char *bf; /**< Buffer to output */
};
@@ -84,6 +85,13 @@ static void ui2a(unsigned long long int num, struct param *p)
int n = 0;
unsigned long long int d = 1;
char *bf = p->bf;
+
+ if (p->hh == 1) {
+ num = (unsigned short int)num;
+ } else if (p->hh == 2) {
+ num = (unsigned char)num;
+ }
+
while (num / d >= p->base)
d *= p->base;
while (d != 0) {
@@ -260,6 +268,7 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va)
p.sign = 0;
p.left = 0;
p.uc = 0;
+ p.hh = 0;
lng = 0;
/* Flags */
@@ -303,6 +312,14 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va)
ch = *(fmt++);
lng = 2;
}
+ } else if (ch == 'h') {
+ ch = *(fmt++);
+ p.hh = 1;
+
+ if (ch == 'h') {
+ ch = *(fmt++);
+ p.hh = 2;
+ }
}
if (ch == 'z') {