headers (2)

This commit is contained in:
bumbread 2022-08-04 20:47:38 +11:00
parent e4f23026f3
commit a35716e34e
11 changed files with 164 additions and 69 deletions

View File

@ -23,7 +23,7 @@ void _Noreturn _assert(
#define assert(c) if (!(c)) __builtin_trap() #define assert(c) if (!(c)) __builtin_trap()
#elif _MSC_VER #elif _MSC_VER
#define assert(c) if (!(c)) __debugbreak() #define assert(c) if (!(c)) __debugbreak()
// TODO: Handle Cuik, and if such handling is not required remove this comment // TODO: Handle Cuik, and if such handling is not required remove this comment
#else #else
// In debug mode there shouldn't be any optimizations so this should // In debug mode there shouldn't be any optimizations so this should
// work as a simple way to cause a trap. // work as a simple way to cause a trap.

View File

@ -1,9 +1,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stdint.h>
#include <limits.h>
#include <wchar.h>
#define PRIi8 "hhi" #define PRIi8 "hhi"
#define PRIu8 "hhu" #define PRIu8 "hhu"
@ -256,6 +254,12 @@
#define SCNxPTR "lx" #define SCNxPTR "lx"
#endif #endif
#if defined(_WIN32)
typedef unsigned short wchar_t;
#else
typedef int wchar_t;
#endif
typedef struct imaxdiv_t imaxdiv_t; typedef struct imaxdiv_t imaxdiv_t;
struct imaxdiv_t { struct imaxdiv_t {
intmax_t quot; intmax_t quot;

14
inc/stdbool.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#if !defined(bool)
#define bool _Bool
#endif
#if !defined(true)
#define true 1
#endif
#if !defined(false)
#define false 0
#endif

View File

@ -9,9 +9,17 @@
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
#define bool _Bool #if !defined(bool)
#define true 1 #define bool _Bool
#define false 0 #endif
#if !defined(true)
#define true 1
#endif
#if !defined(false)
#define false 0
#endif
#define offsetof(st, m) ((size_t)((char *)&((st *)0)->m - (char *)0)) #define offsetof(st, m) ((size_t)((char *)&((st *)0)->m - (char *)0))
#define alignas _Alignas #define alignas _Alignas

View File

@ -2,9 +2,27 @@
#pragma once #pragma once
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
#include <stdint.h> #if !defined(NULL)
#include <uchar.h> #define NULL ((void *)0)
#endif
#if defined(_WIN32)
typedef unsigned long long size_t;
#else
typedef unsigned long size_t;
#endif
#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 struct FILE FILE; typedef struct FILE FILE;

View File

@ -1,12 +1,16 @@
#pragma once #pragma once
#include <stddef.h>
#if !defined(NULL) #if !defined(NULL)
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
#if defined(_WIN32)
typedef unsigned long long size_t;
#else
typedef unsigned long size_t;
#endif
#if !defined(__STDC_LIB_EXT1__) #if !defined(__STDC_LIB_EXT1__)
#define __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__
typedef int errno_t; typedef int errno_t;

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <time.h>
#include <stdbool.h>
#include <stdatomic.h> #include <stdatomic.h>
#if defined(_WIN32) #if defined(_WIN32)
@ -13,29 +11,38 @@
#define ONCE_FLAG_INIT 1 #define ONCE_FLAG_INIT 1
#define TSS_DTOR_ITERATIONS 32 #define TSS_DTOR_ITERATIONS 32
#if !defined(_timespec_defined)
#define _timespec_defined
typedef unsigned long long time_t;
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#endif
#if defined(_WIN32) #if defined(_WIN32)
typedef struct cnd_t { typedef struct cnd_t {
int idk_yet; int idk_yet;
} cnd_t; } cnd_t;
typedef struct thrd_t { typedef struct thrd_t {
void* handle; void* handle;
} thrd_t; } thrd_t;
typedef struct tss_t { typedef struct tss_t {
int idk_yet; int idk_yet;
} tss_t; } tss_t;
typedef struct mtx_t { typedef struct mtx_t {
int type; int type;
// Done to handle recursive mutexes // Done to handle recursive mutexes
unsigned long recursion; unsigned long recursion;
unsigned long owner; unsigned long owner;
atomic_int counter; atomic_int counter;
void* semaphore; void* semaphore;
} mtx_t; } mtx_t;
#else #else
#error "Not implemented" #error "Not implemented"
#endif #endif
typedef void(*tss_dtor_t) (void*); typedef void(*tss_dtor_t) (void*);
@ -85,11 +92,11 @@ int thrd_detach (thrd_t thr);
int thrd_equal (thrd_t thr0, thrd_t thr1); int thrd_equal (thrd_t thr0, thrd_t thr1);
int thrd_join (thrd_t thr, int *res); int thrd_join (thrd_t thr, int *res);
void thrd_yield (void); void thrd_yield (void);
_Noreturn void thrd_exit(int res);
int thrd_sleep( int thrd_sleep(
const struct timespec *duration, const struct timespec *duration,
struct timespec *remaining struct timespec *remaining
); );
_Noreturn void thrd_exit(int res);
int tss_create(tss_t *key, tss_dtor_t dtor); int tss_create(tss_t *key, tss_dtor_t dtor);
void tss_delete(tss_t key); void tss_delete(tss_t key);

View File

@ -3,32 +3,38 @@
#include <stdint.h> #include <stdint.h>
#if !defined(NULL) #if !defined(NULL)
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
#define TIME_UTC 1 #define TIME_UTC 1
#define CLOCKS_PER_SEC ((clock_t)1000000) #define CLOCKS_PER_SEC ((clock_t)1000000)
typedef uint64_t clock_t; typedef unsigned long long clock_t;
typedef uint64_t time_t; typedef unsigned long long time_t;
struct timespec { #if !defined(_timespec_defined)
time_t tv_sec; #define _timespec_defined
long tv_nsec; struct timespec {
}; time_t tv_sec;
long tv_nsec;
};
#endif
struct tm { #if !defined(_tm_defined)
int tm_sec; #define _tm_defined
int tm_min; struct tm {
int tm_hour; int tm_sec;
int tm_mon; int tm_min;
int tm_mday; // Days passed within 1st of current month int tm_hour;
int tm_year; // Years since year 1900 int tm_mon;
int tm_wday; // Days passed since sunday int tm_mday;
int tm_yday; // Days passed since Jan 1 int tm_year;
int tm_isdst; int tm_wday;
}; int tm_yday;
int tm_isdst;
};
#endif
clock_t clock (void); clock_t clock (void);
time_t time (time_t *timer); time_t time (time_t *timer);
@ -48,8 +54,10 @@ size_t strftime(
); );
#ifdef __STDC_WANT_LIB_EXT1__ #ifdef __STDC_WANT_LIB_EXT1__
errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *timeptr); errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *timeptr);
errno_t ctime_s(char *s, rsize_t maxsize, const time_t *timer); errno_t ctime_s (char *s, rsize_t maxsize, const time_t *timer);
struct tm *gmtime_s(const time_t * restrict timer, struct tm * restrict result); struct tm *gmtime_s (const time_t * restrict timer, struct tm * restrict result);
struct tm *localtime_s(const time_t * restrict timer, struct tm * restrict result); struct tm *localtime_s(const time_t * restrict timer, struct tm * restrict result);
#endif #endif

View File

@ -1,8 +1,11 @@
#pragma once #pragma once
#include <stddef.h> #if defined(_WIN32)
#include <stdint.h> typedef unsigned long long size_t;
#else
typedef unsigned long size_t;
#endif
#if !defined(_mbstate_t_defined) #if !defined(_mbstate_t_defined)
#define _mbstate_t_defined #define _mbstate_t_defined
@ -15,8 +18,8 @@
}; };
#endif #endif
typedef uint_least16_t char16_t; typedef unsigned short char16_t;
typedef uint_least32_t char32_t; typedef unsigned int char32_t;
size_t mbrtoc16( size_t mbrtoc16(
char16_t *restrict pc16, char16_t *restrict pc16,

View File

@ -1,19 +1,39 @@
#pragma once #pragma once
#include <stddef.h> #include <locale.h>
#include <stdint.h> #include <stdarg.h>
#include <stdio.h>
#include <time.h> #if !defined(WEOF)
#include <limits.h> #define WEOF -1
#endif
#if !defined(NULL)
#define NULL ((void *)0)
#endif
#if defined(_WIN32) #if defined(_WIN32)
#if !defined(WCHAR_MIN)
#define WCHAR_MIN 0x0000
#endif
#if !defined(WCHAR_MAX)
#define WCHAR_MAX 0xffff
#endif
typedef unsigned short wchar_t; typedef unsigned short wchar_t;
#else #else
#if !defined(WCHAR_MIN)
#define WCHAR_MIN -0x80000000
#endif
#if !defined(WCHAR_MAX)
#define WCHAR_MAX +0x7fffffff
#endif
typedef int wchar_t; typedef int wchar_t;
#endif #endif
typedef int wint_t; typedef int wint_t;
typedef int wint_t;
typedef int (*wctrans_t)(wint_t wc);
typedef int (*wctype_t)(wint_t wc);
#if !defined(_mbstate_t_defined) #if !defined(_mbstate_t_defined)
#define _mbstate_t_defined #define _mbstate_t_defined
@ -26,14 +46,23 @@ typedef int wint_t;
}; };
#endif #endif
// #define WCHAR_MIN 0x0000 #if !defined(_tm_defined)
// #define WCHAR_MAX 0xffff #define _tm_defined
struct tm {
int tm_sec;
#ifndef WEOF int tm_min;
#define WEOF -1 int tm_hour;
int tm_mon;
int tm_mday;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
#endif #endif
typedef struct FILE FILE;
// String length // String length
size_t wcslen(const wchar_t *s); size_t wcslen(const wchar_t *s);

View File

@ -5,7 +5,7 @@ typedef int wint_t;
typedef int (*wctrans_t)(wint_t wc); typedef int (*wctrans_t)(wint_t wc);
typedef int (*wctype_t)(wint_t wc); typedef int (*wctype_t)(wint_t wc);
#ifndef WEOF #if !defined(WEOF)
#define WEOF 0 #define WEOF 0
#endif #endif