2018-12-31 10:49:08 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
|
|
|
// Authors: spectral` //
|
|
|
|
// NeoX //
|
|
|
|
// //
|
2019-01-01 13:09:57 +01:00
|
|
|
// Desc: Kaleid C runtime library //
|
2018-12-31 10:49:08 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-01-01 13:09:57 +01:00
|
|
|
#ifndef _KALCRT_H
|
|
|
|
#define _KALCRT_H
|
2018-12-31 10:49:08 +01:00
|
|
|
|
2019-01-01 13:09:57 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
// Typedefs //
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef __error_t_defined
|
|
|
|
#define __error_t_defined
|
|
|
|
typedef int error_t;
|
2019-01-01 13:09:57 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef __size_t_defined
|
|
|
|
#define __size_t_defined
|
|
|
|
typedef unsigned long size_t;
|
2019-01-01 17:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef __va_list_defined
|
|
|
|
#define __va_list_defined
|
2019-01-01 13:09:57 +01:00
|
|
|
typedef __builtin_va_list va_list;
|
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef __div_t_defined
|
|
|
|
#define __div_t_defined
|
2019-01-01 17:11:30 +01:00
|
|
|
typedef struct { int quot, rem; } div_t;
|
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef __ldiv_t_defined
|
|
|
|
#define __ldiv_t_defined
|
2019-01-01 17:11:30 +01:00
|
|
|
typedef struct { long quot, rem; } ldiv_t;
|
2019-01-01 13:09:57 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
// Global variables //
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-14 23:16:26 +01:00
|
|
|
#ifndef _KALEID_KERNEL
|
|
|
|
|
|
|
|
extern error_t __errno;
|
|
|
|
|
|
|
|
#ifndef errno
|
|
|
|
#define errno __errno
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define __get_errno(x) error_t x = errno;
|
|
|
|
#define __set_errno(x) (errno = (x))
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define errno
|
|
|
|
#define __get_errno(x)
|
|
|
|
#define __set_errno(x)
|
|
|
|
|
|
|
|
#endif
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-01-01 13:09:57 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
// Macros //
|
|
|
|
//------------------------------------------//
|
2018-12-31 10:49:08 +01:00
|
|
|
|
2019-01-01 13:09:57 +01:00
|
|
|
#ifndef _NO_MASK
|
|
|
|
#define _NO_MASK
|
2018-12-31 10:49:08 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------//
|
2019-01-01 13:09:57 +01:00
|
|
|
// va_list utilities //
|
2018-12-31 10:49:08 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-01 13:09:57 +01:00
|
|
|
#ifndef va_start
|
|
|
|
#define va_start __builtin_va_start
|
2018-12-31 10:49:08 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-01 17:11:30 +01:00
|
|
|
#ifndef va_arg
|
|
|
|
#define va_arg __builtin_va_arg
|
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef va_copy
|
|
|
|
#define va_copy __builtin_va_copy
|
2019-01-01 13:09:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef va_end
|
|
|
|
#define va_end __builtin_va_end
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------//
|
|
|
|
// Memory management utilities //
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-02 17:19:13 +01:00
|
|
|
#ifndef memsetb
|
|
|
|
#define memsetb memset
|
2019-01-01 17:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-02 17:19:13 +01:00
|
|
|
#ifndef memchrb
|
|
|
|
#define memchrb memchr
|
2019-01-01 13:09:57 +01:00
|
|
|
#endif
|
2019-01-01 17:11:30 +01:00
|
|
|
|
2019-01-02 17:19:13 +01:00
|
|
|
void *memset(void *, int, size_t);
|
2019-01-01 17:40:48 +01:00
|
|
|
void *memsetw(void *, int, size_t);
|
|
|
|
void *memsetd(void *, int, size_t);
|
|
|
|
void *memsetq(void *, long, size_t);
|
2018-12-31 15:08:56 +01:00
|
|
|
|
2019-01-02 17:19:13 +01:00
|
|
|
void *memchr(const void *, int, size_t);
|
2019-01-01 17:40:48 +01:00
|
|
|
void *memchrw(const void *, int, size_t);
|
|
|
|
void *memchrd(const void *, int, size_t);
|
|
|
|
void *memchrq(const void *, long, size_t);
|
2019-01-01 17:11:30 +01:00
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
void *memrchr(const void *, int, size_t);
|
|
|
|
|
|
|
|
void *memcpy(void *restrict, const void *restrict, size_t);
|
2019-01-01 17:40:48 +01:00
|
|
|
void *memmove(void *, const void *, size_t);
|
2019-01-01 17:11:30 +01:00
|
|
|
|
2019-01-01 17:40:48 +01:00
|
|
|
void *memzero(void *, size_t);
|
|
|
|
int memcmp(const void *, const void *, size_t);
|
2018-12-31 10:49:08 +01:00
|
|
|
|
|
|
|
//------------------------------------------//
|
2019-01-01 13:09:57 +01:00
|
|
|
// String manipulation utilities //
|
2018-12-31 10:49:08 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
size_t strlen(const char *);
|
|
|
|
size_t strspn(const char *, const char *);
|
|
|
|
size_t strcspn(const char *, const char *);
|
|
|
|
|
|
|
|
int strcmp(const char *, const char *);
|
|
|
|
int strncmp(const char *, const char *, size_t);
|
|
|
|
|
|
|
|
char *strchr(const char *, int);
|
|
|
|
char *strrchr(const char *, int);
|
|
|
|
char *strchrnul(const char *, int);
|
|
|
|
|
|
|
|
char *strstr(const char *, const char *);
|
|
|
|
char *strpbrk(const char *, const char *);
|
|
|
|
|
|
|
|
char *strtok(char *restrict, const char *restrict);
|
|
|
|
char *strtok_r(char *restrict, const char *restrict, char **restrict);
|
|
|
|
|
|
|
|
char *strcpy (char *restrict, const char *restrict);
|
|
|
|
char *strncpy (char *restrict, const char *restrict, size_t);
|
2019-01-19 22:36:38 +01:00
|
|
|
int strnzcpy(char *restrict, const char *restrict, size_t);
|
2019-01-14 14:31:49 +01:00
|
|
|
|
|
|
|
char *strcat (char *restrict, const char *restrict);
|
|
|
|
char *strncat (char *restrict, const char *restrict, size_t);
|
2019-01-19 22:36:38 +01:00
|
|
|
int *strnzcat(char *restrict, const char *restrict, size_t);
|
2019-01-14 14:31:49 +01:00
|
|
|
|
|
|
|
char *strrev(char *restrict, const char *restrict);
|
|
|
|
char *strrev2(char *);
|
2018-12-31 10:49:08 +01:00
|
|
|
|
2019-01-01 17:40:48 +01:00
|
|
|
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);
|
2018-12-31 10:49:08 +01:00
|
|
|
|
|
|
|
//------------------------------------------//
|
2019-01-14 14:31:49 +01:00
|
|
|
// Type conversion utilities //
|
2018-12-31 10:49:08 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-01 17:40:48 +01:00
|
|
|
char *itoa(int, char *, int);
|
|
|
|
char *ltoa(long, char *, int);
|
|
|
|
char *utoa(unsigned int, char *, int);
|
|
|
|
char *ultoa(unsigned long, char *, int);
|
2019-01-01 17:11:30 +01:00
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
int atoi(const char *);
|
|
|
|
long atol(const char *);
|
|
|
|
unsigned int atou(const char *);
|
|
|
|
unsigned long atoul(const char *);
|
|
|
|
|
|
|
|
long strtol (const char *restrict, char **restrict, int);
|
|
|
|
unsigned long strtoul(const char *restrict, char **restrict, int);
|
2019-01-01 17:11:30 +01:00
|
|
|
|
|
|
|
//------------------------------------------//
|
|
|
|
// RNG utilities //
|
|
|
|
//------------------------------------------//
|
|
|
|
|
|
|
|
int rand(void);
|
|
|
|
void srand(unsigned int);
|
2018-12-31 10:49:08 +01:00
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
// Time utilities //
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2018-12-31 10:49:08 +01:00
|
|
|
//------------------------------------------//
|
2019-01-01 13:09:57 +01:00
|
|
|
// Diverse utilities //
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
char *strerror(int);
|
|
|
|
char *strsignal(int);
|
2019-01-01 13:09:57 +01:00
|
|
|
|
2019-01-01 17:11:30 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
// Arithmetical macros //
|
|
|
|
//------------------------------------------//
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef __abs
|
|
|
|
#define __abs
|
|
|
|
static inline int abs(int x)
|
|
|
|
{
|
|
|
|
return x < 0 ? -x : x;
|
|
|
|
}
|
2019-01-01 17:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:31:49 +01:00
|
|
|
#ifndef __labs
|
|
|
|
#define __labs
|
|
|
|
static inline long labs(long x)
|
|
|
|
{
|
|
|
|
return x < 0 ? -x : x;
|
|
|
|
}
|
2019-01-01 17:11:30 +01:00
|
|
|
#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
|
|
|
|
|
2019-01-01 13:09:57 +01:00
|
|
|
//------------------------------------------//
|
2019-01-14 14:31:49 +01:00
|
|
|
// End of header //
|
2018-12-31 10:49:08 +01:00
|
|
|
//------------------------------------------//
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|