mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
vendor/libc: a bunch of additions
All these additions are to allow Dear ImGui to be compiled natively.
This commit is contained in:
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *alloca(size_t); /* built-in for gcc */
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
/* built-in for gcc 3 */
|
||||
#undef alloca
|
||||
#undef __alloca
|
||||
#define alloca(size) __alloca(size)
|
||||
#define __alloca(size) __builtin_alloca(size)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Vendored
+12
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define assert(e) ((void)0)
|
||||
#else
|
||||
@@ -14,3 +20,9 @@ void __odin_libc_assert_fail(const char *, const char *, int, const char *);
|
||||
(__builtin_expect(!(e), 0) ? __odin_libc_assert_fail(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
|
||||
|
||||
#endif /* NDEBUG */
|
||||
|
||||
#define static_assert _Static_assert
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
int isdigit(int c);
|
||||
int isblank(int c);
|
||||
int isspace(int c);
|
||||
|
||||
int toupper(int c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Vendored
Vendored
+47
-2
@@ -1,21 +1,66 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define INFINITY (1.0 / 0.0)
|
||||
#define NAN (0.0 / 0.0)
|
||||
|
||||
float sqrtf(float);
|
||||
float cosf(float);
|
||||
float sinf(float);
|
||||
float atan2f(float, float);
|
||||
bool isnan(float);
|
||||
bool isinf(float);
|
||||
|
||||
float floorf(float x);
|
||||
double floor(double x);
|
||||
float ceilf(float x);
|
||||
double ceil(double x);
|
||||
double sqrt(double x);
|
||||
float powf(float x, float y);
|
||||
double pow(double x, double y);
|
||||
float fmodf(float x, float y);
|
||||
double fmod(double x, double y);
|
||||
double cos(double x);
|
||||
float acosf(float x);
|
||||
double acos(double x);
|
||||
float fabsf(float x);
|
||||
double fabs(double x);
|
||||
int abs(int);
|
||||
double ldexp(double, int);
|
||||
double exp(double);
|
||||
float logf(float);
|
||||
double log(double);
|
||||
double sin(double);
|
||||
double trunc(double);
|
||||
double log2(double);
|
||||
double log10(double);
|
||||
double asin(double);
|
||||
double atan(double);
|
||||
double tan(double);
|
||||
double atan2(double, double);
|
||||
double modf(double, double*);
|
||||
|
||||
bool __isnanf(float);
|
||||
bool __isnand(double);
|
||||
#define isnan(x) \
|
||||
( sizeof(x) == sizeof(float) ? __isnanf((float)(x)) \
|
||||
: : __isnand((double)(x)))
|
||||
|
||||
bool __isinff(float);
|
||||
bool __isinfd(double);
|
||||
#define isinf(x) \
|
||||
( sizeof(x) == sizeof(float) ? __isinff((float)(x)) \
|
||||
: : __isinfd((double)(x)))
|
||||
|
||||
bool __isfinitef(float);
|
||||
bool __isfinited(double);
|
||||
#define isfinite(x) \
|
||||
( sizeof(x) == sizeof(float) ? __isfinitef((float)(x)) \
|
||||
: : __isfinited((double)(x)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Vendored
+56
-2
@@ -1,8 +1,14 @@
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <alloca.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {} FILE;
|
||||
|
||||
#define SEEK_SET 0
|
||||
@@ -12,6 +18,8 @@ typedef struct {} FILE;
|
||||
#define stdout ((FILE *)2)
|
||||
#define stderr ((FILE *)3)
|
||||
|
||||
#define EOF -1
|
||||
|
||||
FILE *fopen(const char *, char *);
|
||||
int fclose(FILE *);
|
||||
int fseek(FILE *, long, int);
|
||||
@@ -21,6 +29,10 @@ size_t fwrite(const void *, size_t, size_t, FILE *);
|
||||
|
||||
int vfprintf(FILE *, const char *, va_list);
|
||||
int vsnprintf(char *, size_t, const char *, va_list);
|
||||
int vsprintf(char *, const char *, va_list);
|
||||
|
||||
int putchar(int ch);
|
||||
int getchar();
|
||||
|
||||
static inline int snprintf(char *buf, size_t size, const char *fmt, ...) {
|
||||
va_list args;
|
||||
@@ -30,6 +42,14 @@ static inline int snprintf(char *buf, size_t size, const char *fmt, ...) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int sprintf(char *buf, const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int result = vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int fprintf(FILE *f, const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
@@ -45,3 +65,37 @@ static inline int printf(const char *fmt, ...) {
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int __sscanf(const char *str, const char *format, void *ptrs);
|
||||
|
||||
static inline int vsscanf(const char *str, const char *format, va_list ap) {
|
||||
int count = 0;
|
||||
for (int i = 0; format[i]; i++) {
|
||||
if (format[i] == '%') {
|
||||
if (format[i+1] == '%') {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
void **ptrs = (void **)(alloca(count*sizeof(void *)));
|
||||
for (int i = 0; i < count; i++) {
|
||||
ptrs[i] = va_arg(ap, void *);
|
||||
}
|
||||
|
||||
return __sscanf(str, format, ptrs);
|
||||
}
|
||||
|
||||
static inline int sscanf(const char *str, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int res = vsscanf(str, format, args);
|
||||
va_end(args);
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Vendored
+25
@@ -1,3 +1,9 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *malloc(size_t size);
|
||||
@@ -17,3 +23,22 @@ long long atoll(const char *);
|
||||
double atof(const char *);
|
||||
|
||||
long strtol(const char *, char **, int);
|
||||
double strtod(const char *, char **);
|
||||
|
||||
void abort();
|
||||
void exit(int exit_code);
|
||||
|
||||
#define ATEXIT_MAX 32
|
||||
|
||||
int atexit(typeof(void (void)) *);
|
||||
|
||||
typedef struct {
|
||||
long int quot;
|
||||
long int rem;
|
||||
} ldiv_t;
|
||||
|
||||
ldiv_t ldiv(long int number, long int denom);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Vendored
+11
@@ -1,9 +1,16 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *memcpy(void *, const void *, size_t);
|
||||
void *memset(void *, int, size_t);
|
||||
void *memmove(void *, void *, size_t);
|
||||
int memcmp(const void *, const void *, size_t);
|
||||
void *memchr(const void *, int, size_t);
|
||||
|
||||
unsigned long strlen(const char *str);
|
||||
|
||||
@@ -19,3 +26,7 @@ int strcmp(const char *, const char *);
|
||||
int strncmp(const char *, const char *, size_t);
|
||||
|
||||
char *strstr(const char *, const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int64_t clock_t;
|
||||
typedef clock_t time_t;
|
||||
|
||||
clock_t clock();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user