From: Vincent Dagonneau <v@vda.io>
To: linux-kernel@vger.kernel.org
Cc: w@1wt.eu, Vincent Dagonneau <v@vda.io>
Subject: [PATCH v4 2/4] tools/nolibc: Adding integer types and integer limit macros
Date: Wed, 8 Feb 2023 21:40:42 -0500 [thread overview]
Message-ID: <20230209024044.13127-3-v@vda.io> (raw)
In-Reply-To: <20230209024044.13127-1-v@vda.io>
This commit adds some of the missing integer types to stdint.h and adds
limit macros (e.g. INTN_{MIN,MAX}).
The reference used for adding these types is
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdint.h.html.
Note that the maximum size of size_t is implementation-defined (>65535),
in this case I chose to stick with what the kernel uses in
linux/include/uapi/asm-generic/posix_types.h: unsigned int on 32bits and
unsigned long on 64bits.
Signed-off-by: Vincent Dagonneau <v@vda.io>
---
tools/include/nolibc/stdint.h | 60 +++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/tools/include/nolibc/stdint.h b/tools/include/nolibc/stdint.h
index 4ba264031df9..6a7683de09ec 100644
--- a/tools/include/nolibc/stdint.h
+++ b/tools/include/nolibc/stdint.h
@@ -21,4 +21,64 @@ typedef unsigned long uintptr_t;
typedef signed long intptr_t;
typedef signed long ptrdiff_t;
+typedef int8_t int_least8_t;
+typedef uint8_t uint_least8_t;
+typedef int16_t int_least16_t;
+typedef uint16_t uint_least16_t;
+typedef int32_t int_least32_t;
+typedef uint32_t uint_least32_t;
+typedef int64_t int_least64_t;
+typedef uint64_t uint_least64_t;
+
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+
+/* limits of integral types */
+
+#define INT8_MIN (-128)
+#define INT16_MIN (-32767-1)
+#define INT32_MIN (-2147483647-1)
+#define INT64_MIN (-9223372036854775807LL-1)
+
+#define INT8_MAX (127)
+#define INT16_MAX (32767)
+#define INT32_MAX (2147483647)
+#define INT64_MAX (9223372036854775807LL)
+
+#define UINT8_MAX (255)
+#define UINT16_MAX (65535)
+#define UINT32_MAX (4294967295U)
+#define UINT64_MAX (18446744073709551615ULL)
+
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST64_MIN INT64_MIN
+
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MAX INT64_MAX
+
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#if __WORDSIZE == 64
+ #define SIZE_MAX UINT64_MAX
+ #define INTPTR_MIN INT64_MIN
+ #define INTPTR_MAX INT64_MAX
+ #define UINTPTR_MAX UINT64_MAX
+ #define PTRDIFF_MIN INT64_MIN
+ #define PTRDIFF_MAX INT64_MAX
+#else
+ #define SIZE_MAX UINT32_MAX
+ #define INTPTR_MIN INT32_MIN
+ #define INTPTR_MAX INT32_MAX
+ #define UINTPTR_MAX UINT32_MAX
+ #define PTRDIFF_MIN INT32_MIN
+ #define PTRDIFF_MAX INT32_MAX
+#endif /* __WORDSIZE == 64 */
+
#endif /* _NOLIBC_STDINT_H */
--
2.39.1
next prev parent reply other threads:[~2023-02-09 2:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 2:40 [PATCH v4 0/4] tools/nolibc: Adding stdint.h, more integer types and tests Vincent Dagonneau
2023-02-09 2:40 ` [PATCH v4 1/4] tools/nolibc: Adding stdint.h Vincent Dagonneau
2023-02-09 2:40 ` Vincent Dagonneau [this message]
2023-02-09 2:40 ` [PATCH v4 3/4] tools/nolibc: Enlarging column width of tests Vincent Dagonneau
2023-02-09 2:40 ` [PATCH v4 4/4] tools/nolibc: Adds tests for the integer limits in stdint.h Vincent Dagonneau
2023-02-09 3:43 ` [PATCH v4 0/4] tools/nolibc: Adding stdint.h, more integer types and tests Willy Tarreau
2023-02-10 13:03 ` Vincent Dagonneau
2023-02-12 10:41 ` Willy Tarreau
2023-02-12 18:27 ` Willy Tarreau
2023-02-16 0:11 ` Vincent Dagonneau
2023-02-16 3:29 ` Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230209024044.13127-3-v@vda.io \
--to=v@vda.io \
--cc=linux-kernel@vger.kernel.org \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox