tools/nolibc: Add stdint.h
PATCH 1/1 tools/nolibc: Add stdint.h
Hi,
I was testing out nolibc with some simple programs originally linked against glibc. I noticed a quick fix for some of them was to have an stdint.h with limits macros.
Here are the changes I made. I've got a couple more ideas for fleshing out nolibc, let me know if you are interested in contributions.
Add stdint.h and moved the relevant definitions from std.h. Also added macros for limits and *_least_* types.
--- tools/include/nolibc/std.h | 15 +------ tools/include/nolibc/stdint.h | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 tools/include/nolibc/stdint.h
tools/include/nolibc/std.h +1 -14
@@ -18,20 +18,7 @@#define NULL ((void *)0)#endif -/* stdint types */ -typedef unsigned char uint8_t ; -typedef signed char int8_t ; -typedef unsigned short uint16_t ; -typedef signed short int16_t ; -typedef unsigned int uint32_t ; -typedef signed int int32_t ; -typedef unsigned long long uint64_t ; -typedef signed long long int64_t ; -typedef unsigned long size_t ; -typedef signed long ssize_t ; -typedef unsigned long uintptr_t ; -typedef signed long intptr_t ; -typedef signed long ptrdiff_t ; +#include <stdint.h> /* those are commonly provided by sys/types.h */ typedef unsigned int dev_t ;
tools/include/nolibc/stdint.h new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.39.1
Thomas Weißschuh
maintainerQuoted 31 lines · Vincent Dagonneau
Hi,
I was testing out nolibc with some simple programs originally linked against glibc. I noticed a quick fix for some of them was to have an
stdint.hwith limits macros.Here are the changes I made. I've got a couple more ideas for fleshing out nolibc, let me know if you are interested in contributions.
Add
stdint.hand moved the relevant definitions fromstd.h. Also added macros for limits and *_least_* types.--- tools/include/nolibc/std.h | 15 +------ tools/include/nolibc/stdint.h | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 tools/include/nolibc/stdint.htools/include/nolibc/std.h +0
-5@@ -18,20 +18,7 @@#define NULL ((void *)0)#endif -/* stdint types */ -typedef unsigned char uint8_t ; -typedef signed char int8_t ; -typedef unsigned short uint16_t ; -typedef signed short int16_t ;
tools/include/nolibc/std.h line 21
Quoted 10 lines
tools/include/nolibc/std.h +1
-9-typedef unsigned int uint32_t ; -typedef signed int int32_t ; -typedef unsigned long long uint64_t ; -typedef signed long long int64_t ; -typedef unsigned long size_t ; -typedef signed long ssize_t ; -typedef unsigned long uintptr_t ; -typedef signed long intptr_t ; -typedef signed long ptrdiff_t ; +#include <stdint.h>
Shouldn't this be
#include "stdint.h"?
Quoted 54 lines
tools/include/nolibc/std.h +0
-0/* those are commonly provided by sys/types.h */ typedef unsigned int dev_t ;tools/include/nolibc/stdint.h new file +46
-0@@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* Standard definitions and types for NOLIBC +* Copyright (C) 2023 Vincent Dagonneau <[email protected]> +*/ + +#ifndef _NOLIBC_STDINT_H +#define _NOLIBC_STDINT_H + +typedef unsigned char uint8_t ; +typedef signed char int8_t ; +typedef unsigned short uint16_t ; +typedef signed short int16_t ; +typedef unsigned int uint32_t ; +typedef signed int int32_t ; +typedef unsigned long long uint64_t ; +typedef signed long long int64_t ; +typedef unsigned long size_t ; +typedef signed long ssize_t ; +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 (-9223372036854775807-1) + +#define INT8_MAX (127) +#define INT16_MAX (32767) +#define INT32_MAX (2147483647) +#define INT64_MAX (9223372036854775807)
tools/include/nolibc/stdint.h line 56
Quoted 10 lines
tools/include/nolibc/stdint.h new file +10
-0+ +#define UINT8_MAX (255) +#define UINT16_MAX (65535) +#define UINT32_MAX (4294967295U) +#define UINT64_MAX (18446744073709551615) + +#define INT_LEAST8_MIN (-128) +#define INT_LEAST16_MIN (-32767-1) +#define INT_LEAST32_MIN (-2147483647-1) +#define INT_LEAST64_MIN (-9223372036854775807-1)
As int_least8_t is a typedef to int8_t, you could use
#define INT_LEAST8_MIN INT8_MIN
etc.
Quoted 8 lines
tools/include/nolibc/stdint.h new file +8
-0+#define INT_LEAST8_MAX (127) +#define INT_LEAST16_MAX (32767) +#define INT_LEAST32_MAX (2147483647) +#define INT_LEAST64_MAX (9223372036854775807) + +#define UINT_LEAST8_MAX (255) +#define UINT_LEAST16_MAX (65535) +#define UINT_LEAST32_MAX (4294967295U)
tools/include/nolibc/stdint.h line 75
Quoted 10 lines
tools/include/nolibc/stdint.h new file +10
-0+#define UINT_LEAST64_MAX (18446744073709551615) + +#define SIZE_MAX (18446744073709551615UL) + +#define INTPTR_MIN (-9223372036854775807L-1) +#define INTPTR_MAX (9223372036854775807L) +#define UINTPTR_MAX (18446744073709551615UL) + +#define PTRDIFF_MIN (-9223372036854775807L-1) +#define PTRDIFF_MAX (9223372036854775807L)
The above break on 32 bit.
Quoted 4 lines
tools/include/nolibc/stdint.h new file +1
-0+#endif /* _NOLIBC_STDINT_H */ Signature · 1 line
2.39.1