55 lines
1.6 KiB
C
55 lines
1.6 KiB
C
#ifndef KARLOS_STD_H
|
|
#define KARLOS_STD_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
// Memory functions
|
|
void *memset(void *ptr, int value, size_t num);
|
|
void *memcpy(void *dest, const void *src, size_t n);
|
|
int memcmp(const void *ptr, const void *ptr2, size_t num);
|
|
void *memmove(void *dest, const void *src, size_t num);
|
|
|
|
// String functions
|
|
unsigned int strlen(const char *s);
|
|
bool streq(const char *a, const char *b);
|
|
bool strcontains(const char *s, char c);
|
|
|
|
// Low-level output functions
|
|
void putc(char c);
|
|
void putln(void);
|
|
void puts(const char *s);
|
|
void putsln(const char *s);
|
|
void put_charbuf(const char *buf, unsigned int len);
|
|
void putu8x(uint8_t value);
|
|
void putu16x(uint16_t value);
|
|
void putu32x(uint32_t value);
|
|
void putu64x(uint64_t value);
|
|
|
|
// String and conversion utilities
|
|
void itoa(int value, unsigned int base, char *buffer);
|
|
void utoa(unsigned int value, unsigned int base, char *buffer);
|
|
void itoa_ll(long long value, unsigned int base, char *buffer);
|
|
void utoa_ll(unsigned long long value, unsigned int base, char *buffer);
|
|
unsigned int toa_buf_size(unsigned int bits, unsigned int base);
|
|
|
|
// Formatted output
|
|
void printf(const char *format, ...);
|
|
|
|
// Debug helpers
|
|
#define PANIC(msg) panic(__FILE__, __LINE__, msg)
|
|
#define ASSERT(cond) do {\
|
|
if (!(cond)) {\
|
|
PANIC("assertion failed: " #cond);\
|
|
}\
|
|
} while (0)
|
|
#define TODO() PANIC("not implemented")
|
|
#define UNREACHABLE() PANIC("unreachable")
|
|
// don't use this directly, use the macros above
|
|
__attribute__ ((noreturn))
|
|
void panic(const char *file, unsigned int line, const char *msg);
|
|
|
|
#define STATIC_ASSERT(expr) _Static_assert(expr)
|
|
|
|
#endif // KARLOS_UTILITY_H
|