From a8594606c332daa15ee408a208ad7d06ccddfdee Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Mon, 14 Apr 2025 17:47:58 -0400 Subject: [PATCH] Remove reliance on system stdint.h header --- arch/aarch64.c | 2 +- arch/mips.c | 2 +- arch/x86_64.c | 2 +- buildtest.c | 2 +- int.h | 23 +++++++++++++++++++++++ sys.h | 2 +- 6 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 int.h diff --git a/arch/aarch64.c b/arch/aarch64.c index ab1701f..6a953c4 100644 --- a/arch/aarch64.c +++ b/arch/aarch64.c @@ -1,5 +1,5 @@ #if defined(__aarch64__) -#include +#include "../int.h" void exit(int8_t status){ asm ( "mov x0, %0\n" // Move the exit status into register x0 diff --git a/arch/mips.c b/arch/mips.c index 301489b..ec7e14e 100644 --- a/arch/mips.c +++ b/arch/mips.c @@ -1,5 +1,5 @@ #if defined(__mips__) -#include +#include "../int.h" void exit(int8_t status){ asm ( diff --git a/arch/x86_64.c b/arch/x86_64.c index 383c355..a04875c 100644 --- a/arch/x86_64.c +++ b/arch/x86_64.c @@ -1,5 +1,5 @@ -#include #if defined(__x86_64__) +#include "../int.h" #define SYS_EXIT 60 void exit(int8_t status) { diff --git a/buildtest.c b/buildtest.c index 8553dd8..9d659fe 100644 --- a/buildtest.c +++ b/buildtest.c @@ -1,4 +1,4 @@ -#include +#include "int.h" #include "sys.h" diff --git a/int.h b/int.h new file mode 100644 index 0000000..c45e937 --- /dev/null +++ b/int.h @@ -0,0 +1,23 @@ +#if defined(__x86_64__) || defined(__aarch64__) +#define __WORDSIZE 64 +#elif defined(__mips__) +#define __WORDSIZE 32 +#endif + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long uint64_t; + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long int64_t; + +#if __WORDSIZE == 64 +typedef long intptr_t; +typedef unsigned long uintptr_t; +#elif __WORDSIZE == 32 +typedef int intptr_t; +typedef unsigned int uintptr_t; +#endif diff --git a/sys.h b/sys.h index 151ff79..057bd51 100644 --- a/sys.h +++ b/sys.h @@ -1,5 +1,5 @@ #ifndef MINIMALSYS_H -#include +#include "int.h" void exit(int8_t status);