From e4f23026f3192e781a92f39aefcc93dfdcb6e507 Mon Sep 17 00:00:00 2001 From: bumbread Date: Thu, 4 Aug 2022 20:00:01 +1100 Subject: [PATCH] remove types --- inc/{stdatomic.h => _stdatomic.h} | 0 inc/limits.h | 18 ++++++++++++++++-- inc/stddef.h | 25 +++++++++++++++++-------- inc/stdlib.h | 8 ++++++-- inc/types/mbstate.h | 11 ----------- inc/types/size.h | 8 -------- inc/types/wchar.h | 2 -- inc/uchar.h | 13 +++++++++++-- inc/wchar.h | 19 ++++++++++++++++++- 9 files changed, 68 insertions(+), 36 deletions(-) rename inc/{stdatomic.h => _stdatomic.h} (100%) delete mode 100644 inc/types/mbstate.h delete mode 100644 inc/types/size.h delete mode 100644 inc/types/wchar.h diff --git a/inc/stdatomic.h b/inc/_stdatomic.h similarity index 100% rename from inc/stdatomic.h rename to inc/_stdatomic.h diff --git a/inc/limits.h b/inc/limits.h index 7719eb8..f6cf8c9 100644 --- a/inc/limits.h +++ b/inc/limits.h @@ -68,5 +68,19 @@ #define WINT_MAX INT_MAX #define WCHAR_WIDTH USHORT_WIDTH -#define WCHAR_MIN USHORT_WIDTH -#define WCHAR_MAX USHORT_WIDTH + +#if !defined(WCHAR_MIN) + #if defined(_WIN32) + #define WCHAR_MIN 0 + #else + #define WCHAR_MIN INT_MIN + #endif +#endif + +#if !defined(WCHAR_MAX) + #if defined(_WIN32) + #define WCHAR_MAX USHORT_MAX + #else + #define WCHAR_MAX INT_MAX + #endif +#endif diff --git a/inc/stddef.h b/inc/stddef.h index 5a0fb73..0a936e3 100644 --- a/inc/stddef.h +++ b/inc/stddef.h @@ -1,23 +1,19 @@ #pragma once -#include - #define __bool_true_false_are_defined 1 #define __alignas_is_defined 1 #define __alignof_is_defined 1 -#define NULL ((void *)0) -#define offsetof(st, m) ((size_t)((char *)&((st *)0)->m - (char *)0)) - -typedef long long ptrdiff_t; -typedef long long max_align_t; -typedef unsigned short wchar_t; // +#if !defined(NULL) + #define NULL ((void *)0) +#endif #define bool _Bool #define true 1 #define false 0 +#define offsetof(st, m) ((size_t)((char *)&((st *)0)->m - (char *)0)) #define alignas _Alignas #define alignof _Alignof @@ -26,3 +22,16 @@ typedef unsigned short wchar_t; // #else #define noreturn declspec(noreturn) #endif + +#if defined(_WIN32) + typedef long long ptrdiff_t; + typedef unsigned long long size_t; + typedef unsigned long long max_align_t; + typedef unsigned short wchar_t; +#else + typedef long ptrdiff_t; + typedef unsigned long size_t; + typedef unsigned long max_align_t; + typedef int wchar_t; +#endif + diff --git a/inc/stdlib.h b/inc/stdlib.h index 3372ab4..1bae0f6 100644 --- a/inc/stdlib.h +++ b/inc/stdlib.h @@ -10,8 +10,6 @@ #endif #endif -#include - #if !defined(NULL) #define NULL ((void *)0) #endif @@ -19,6 +17,12 @@ #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 +#if defined(_WIN32) + typedef unsigned long long size_t; +#else + typedef unsigned long size_t; +#endif + typedef struct div_t { int quot; int rem; diff --git a/inc/types/mbstate.h b/inc/types/mbstate.h deleted file mode 100644 index 85494c3..0000000 --- a/inc/types/mbstate.h +++ /dev/null @@ -1,11 +0,0 @@ - -#pragma once - -typedef struct mbstate_t mbstate_t; -struct mbstate_t { - union { - unsigned short leftover; - unsigned short high_surrogate; - }; -}; - diff --git a/inc/types/size.h b/inc/types/size.h deleted file mode 100644 index befa3c6..0000000 --- a/inc/types/size.h +++ /dev/null @@ -1,8 +0,0 @@ - -#pragma once - -#if defined(_MSC_VER) - typedef unsigned long long size_t; -#else - typedef unsigned long size_t; -#endif diff --git a/inc/types/wchar.h b/inc/types/wchar.h deleted file mode 100644 index 139597f..0000000 --- a/inc/types/wchar.h +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/inc/uchar.h b/inc/uchar.h index 29dbcd4..f645214 100644 --- a/inc/uchar.h +++ b/inc/uchar.h @@ -1,11 +1,20 @@ #pragma once -#include - #include #include +#if !defined(_mbstate_t_defined) + #define _mbstate_t_defined + typedef struct mbstate_t mbstate_t; + struct mbstate_t { + union { + unsigned short leftover; + unsigned short high_surrogate; + }; + }; +#endif + typedef uint_least16_t char16_t; typedef uint_least32_t char32_t; diff --git a/inc/wchar.h b/inc/wchar.h index c10c627..4079e87 100644 --- a/inc/wchar.h +++ b/inc/wchar.h @@ -1,18 +1,35 @@ #pragma once -#include #include #include #include #include #include +#if defined(_WIN32) + typedef unsigned short wchar_t; +#else + typedef int wchar_t; +#endif + typedef int wint_t; +#if !defined(_mbstate_t_defined) + #define _mbstate_t_defined + typedef struct mbstate_t mbstate_t; + struct mbstate_t { + union { + unsigned short leftover; + unsigned short high_surrogate; + }; + }; +#endif + // #define WCHAR_MIN 0x0000 // #define WCHAR_MAX 0xffff + #ifndef WEOF #define WEOF -1 #endif