//----------------------------------------------------------------------------// // GNU GPL OS/K // // // // Authors: spectral` // // NeoX // // // // Desc: Kaleid C runtime library // //----------------------------------------------------------------------------// #ifndef _KALCRT_H #define _KALCRT_H //------------------------------------------// // Typedefs // //------------------------------------------// #ifndef __size_t #define __size_t typedef unsigned long size_t; #endif #ifndef __status_t #define __status_t typedef signed long status_t; #endif #ifndef __va_list #define __va_list typedef __builtin_va_list va_list; #endif #ifndef __div_t #define __div_t typedef struct { int quot, rem; } div_t; #endif #ifndef __ldiv_t #define __ldiv_t typedef struct { long quot, rem; } ldiv_t; #endif //------------------------------------------// // Macros // //------------------------------------------// #ifndef _NO_MASK #define _NO_MASK #endif //------------------------------------------// // va_list utilities // //------------------------------------------// #ifndef va_start #define va_start __builtin_va_start #endif #ifndef va_arg #define va_arg __builtin_va_arg #endif #ifndef va_next #define va_next __builtin_va_next #endif #ifndef va_end #define va_end __builtin_va_end #endif //------------------------------------------// // Memory management utilities // //------------------------------------------// #ifndef memsetb #define memsetb memset #endif #ifndef memchrb #define memchrb memchr #endif void *memset(void *, int, size_t); void *memsetw(void *, int, size_t); void *memsetd(void *, int, size_t); void *memsetq(void *, long, size_t); void *memchr(const void *, int, size_t); void *memchrw(const void *, int, size_t); void *memchrd(const void *, int, size_t); void *memchrq(const void *, long, size_t); void *memcpy(void *, const void *, size_t); void *memmove(void *, const void *, size_t); void *memzero(void *, size_t); int memcmp(const void *, const void *, size_t); //------------------------------------------// // String manipulation utilities // //------------------------------------------// size_t strlen(const char *); char *strcpy(char *, const char *); char *strncpy(char *, const char *, size_t); char *strrev(char *, const char *); char *reverse(char *); int sprintf(char *, const char *, ...); int snprintf(char *, size_t, const char *, ...); int vsprintf(char *, const char *, va_list); int vsnprintf(char *, size_t, const char *, va_list); //------------------------------------------// // Type conversion utilities // //------------------------------------------// int *atoi(const char *); long *atol(const char *); char *itoa(int, char *, int); char *ltoa(long, char *, int); char *utoa(unsigned int, char *, int); char *ultoa(unsigned long, char *, int); long strtol(const char *, char **, int); unsigned long strtoul(const char *, char **, int); //------------------------------------------// // RNG utilities // //------------------------------------------// int rand(void); void srand(unsigned int); //------------------------------------------// // Diverse utilities // //------------------------------------------// const char *describe_status(status_t) _NO_MASK; //------------------------------------------// // Arithmetical macros // //------------------------------------------// #ifndef abs #define abs(x) ((x) < 0 ? -x : x) #endif #ifndef labs #define labs(x) ((x) < 0 ? -x : x) #endif #ifndef min #define min(x,y) ((x) < (y) ? (x) : (y)) #endif #ifndef lmin #define lmin(x,y) ((x) < (y) ? (x) : (y)) #endif #ifndef max #define max(x,y) ((x) < (y) ? (x) : (y)) #endif #ifndef lmax #define lmax(x,y) ((x) < (y) ? (x) : (y)) #endif #ifndef __div #define __div static inline div_t div(int __x, int __y) { div_t __res; __res.quot = __x/__y; __res.rem = __x%__y; return __res; } #endif #ifndef __ldiv #define __ldiv static inline ldiv_t ldiv(long __x, long __y) { ldiv_t __res; __res.quot = __x/__y; __res.rem = __x%__y; return __res; } #endif //------------------------------------------// // End of // //------------------------------------------// #endif