This commit is contained in:
alexvoste
2026-05-07 02:22:25 +03:00
commit 1a9fd27a31
226 changed files with 29188 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
#ifndef _CTYPE_H
#define _CTYPE_H
int isalnum(int c);
int isalpha(int c);
int isblank(int c);
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isupper(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isxdigit(int c);
int tolower(int c);
int toupper(int c);
#endif
+62
View File
@@ -0,0 +1,62 @@
#ifndef _MATH_H
#define _MATH_H
#include <stdint.h>
int abs(int x);
double fabs(double x);
double pow(double base, double exp);
double pow10(int n);
int isinf(double x);
int isnan(double x);
static inline double floor(double x) {
int64_t i = (int64_t)x;
return (double)(i - (x < (double)i));
}
static inline double ceil(double x) {
int64_t i = (int64_t)x;
return (double)(i + (x > (double)i));
}
static inline double round(double x) {
return (x >= 0.0) ? floor(x + 0.5) : ceil(x - 0.5);
}
static inline double sqrt(double x) {
double result;
asm volatile ("sqrtsd %1, %0" : "=x"(result) : "x"(x));
return result;
}
static inline float sqrtf(float x) {
float result;
asm volatile ("sqrtss %1, %0" : "=x"(result) : "x"(x));
return result;
}
static inline double log2(double x) {
double result;
asm volatile (
"fld1\n\t"
"fld %1\n\t"
"fyl2x\n\t"
"fstp %0\n\t"
: "=m"(result) : "m"(x)
);
return result;
}
#define MIN(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b; })
#define MAX(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b; })
#define ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
#define ALIGN_DOWN(x, align) ((x) & ~((align) - 1))
#define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
#define INFINITY (1.0/0.0)
#define NAN (0.0/0.0)
#endif
+44
View File
@@ -0,0 +1,44 @@
#ifndef _STDIO_H
#define _STDIO_H
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#define EOF (-1)
#define MAX_SCROLL_LINES 1000
int putchar(int c);
int puts(const char *str);
int printf(const char *format, ...);
int sprintf (char* restrict buf, const char* restrict fmt, ...);
int snprintf(char* restrict buf, size_t size, const char* restrict fmt, ...);
int vsprintf (char* restrict buf, const char* restrict fmt, va_list ap);
int vsnprintf(char* restrict buf, size_t size, const char* restrict fmt, va_list ap);
int vprintf(const char* restrict fmt, va_list ap);
int getchar(void);
int scanf (const char * restrict fmt, ...);
int vscanf(const char * restrict fmt, va_list ap);
int sscanf (const char * restrict str, const char * restrict fmt, ...);
int vsscanf(const char *str, const char *fmt, va_list ap);
extern uint32_t cursor_x;
extern uint32_t cursor_y;
extern uint32_t text_color;
extern uint32_t bg_color;
void scroll_screen(int lines);
uint32_t get_screen_width(void);
uint32_t get_screen_height(void);
void set_cursor_position(uint32_t x, uint32_t y);
void get_cursor_position(uint32_t *x, uint32_t *y);
void set_text_color(uint32_t color);
void clear_screen(void);
void scroll_up(int lines);
#endif
+30
View File
@@ -0,0 +1,30 @@
#ifndef _STDLIB_H
#define _STDLIB_H
#include <stddef.h>
#include <math.h>
char* itoa(int val, char* restrict str, int base);
long strtol (const char * restrict s, char ** restrict end, int base);
unsigned long strtoul (const char * restrict s, char ** restrict end, int base);
long long strtoll (const char * restrict s, char ** restrict end, int base);
unsigned long long strtoull(const char * restrict s, char ** restrict end, int base);
static inline int atoi(const char* s) { return (int)strtol (s, (char**)0, 10); }
static inline long atol(const char* s) { return strtol (s, (char**)0, 10); }
void* malloc (size_t size);
void* calloc (size_t nmemb, size_t size);
void* realloc(void* ptr, size_t size);
void free (void* ptr);
void* aligned_alloc(size_t alignment, size_t size);
void aligned_free (void* ptr);
static inline void abort(void) {
__asm__ volatile ("cli; hlt");
__builtin_unreachable();
}
#endif
+45
View File
@@ -0,0 +1,45 @@
#ifndef _STRING_H
#define _STRING_H
#include <stddef.h>
#include <stdint.h>
void* memcpy (void* restrict dst, const void* restrict src, size_t n);
void* memmove(void* dst, const void* src, size_t n);
void* memset (void* dst, int c, size_t n);
int memcmp (const void* a, const void* b, size_t n);
void *memchr(void *p, int val, size_t n);
void *rawmemchr(void *p, int c);
void* memset_explicit(void* dst, int c, size_t n);
size_t strlen (const char* s);
size_t strnlen(const char* s, size_t maxlen);
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t n);
char *strcat(char *dest, const char *src);
char* strncat(char* restrict dst, const char* restrict src, size_t n);
int strcmp (const char* a, const char* b);
int strncmp(const char* a, const char* b, size_t n);
char* strchr (const char* s, int c);
char* strrchr(const char* s, int c);
char* strstr (const char* haystack, const char* needle);
char* strpbrk(const char* s, const char* accept);
size_t strspn (const char* s, const char* accept);
size_t strcspn(const char* s, const char* reject);
char *strtok(char *str, const char *delim);
long strtol (const char* restrict s, char** restrict end, int base);
unsigned long strtoul(const char* restrict s, char** restrict end, int base);
char* strdup(const char* s);
static inline void bzero(void* s, size_t n) {
memset(s, 0, n);
}
#endif