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
+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
|
||||
|
||||
Reference in New Issue
Block a user