1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/kaleid/include/base/crtlib.h

311 lines
8.1 KiB
C
Raw Normal View History

2019-01-21 15:00:04 +01:00
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
2019-02-16 23:36:33 +01:00
// Desc: C Runtime Library //
2019-01-21 15:00:04 +01:00
// //
2019-02-16 23:36:33 +01:00
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
2019-01-21 15:00:04 +01:00
//----------------------------------------------------------------------------//
#ifndef _KALBASE_CRTLIB_H
#define _KALBASE_CRTLIB_H
2019-02-16 23:36:33 +01:00
#ifdef __cplusplus
extern "C" {
#endif
2019-01-21 15:00:04 +01:00
//------------------------------------------//
#ifndef __error_t_defined
#define __error_t_defined
typedef int error_t;
#endif
#ifndef __size_t_defined
#define __size_t_defined
typedef unsigned long size_t;
#endif
#ifndef __va_list_defined
#define __va_list_defined
typedef __builtin_va_list va_list;
#endif
#ifndef __osk_div_t_defined
#define __osk_div_t_defined
2019-01-21 15:00:04 +01:00
typedef struct { int quot, rem; } div_t;
#endif
#ifndef __osk_ldiv_t_defined
#define __osk_ldiv_t_defined
2019-01-21 15:00:04 +01:00
typedef struct { long quot, rem; } ldiv_t;
#endif
//------------------------------------------//
#ifndef _KALEID_KERNEL
extern error_t __errno;
#ifndef errno
#define errno __errno
#endif
2019-03-18 17:25:44 +01:00
#define __get_errno(x) error_t x = errno
2019-01-21 15:00:04 +01:00
#define __set_errno(x) (errno = (x))
#else
#define errno
#define __get_errno(x)
#define __set_errno(x)
#endif
//------------------------------------------//
#ifndef _NO_MASK
#define _NO_MASK
#endif
//------------------------------------------//
#ifndef va_start
#define va_start __builtin_va_start
#endif
#ifndef va_arg
#define va_arg __builtin_va_arg
#endif
#ifndef va_copy
#define va_copy __builtin_va_copy
#endif
#ifndef va_end
#define va_end __builtin_va_end
#endif
//------------------------------------------//
#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);
2019-02-06 14:07:38 +01:00
/*
2019-01-21 15:00:04 +01:00
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);
2019-02-06 14:07:38 +01:00
*/
2019-01-21 15:00:04 +01:00
void *memrchr(const void *, int, size_t);
void *memcpy(void *restrict, const void *restrict, size_t);
void *memmove(void *, const void *, size_t);
void *memzero(void *, size_t);
int memcmp(const void *, const void *, size_t);
//------------------------------------------//
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);
char *strnzcpy(char *restrict, const char *restrict, size_t);
2019-01-21 15:00:04 +01:00
char *strcat(char *restrict, const char *restrict);
char *strncat(char *restrict, const char *restrict, size_t);
char *strnzcat(char *restrict, const char *restrict, size_t);
2019-01-21 15:00:04 +01:00
char *strrev(char *restrict, const char *restrict);
char *strrev2(char *);
size_t sprintf(char *, const char *, ...);
size_t snprintf(char *, size_t, const char *, ...);
size_t vsprintf(char *, const char *, va_list);
size_t vsnprintf(char *, size_t, const char *, va_list);
2019-01-21 15:00:04 +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-21 15:00:04 +01:00
int atoi(const char *);
long atol(const char *);
long strtol(const char *restrict, char **restrict, int);
2019-01-21 15:00:04 +01:00
unsigned int atou(const char *);
unsigned long atoul(const char *);
unsigned long strtoul(const char *restrict, char **restrict, int);
2019-01-21 15:00:04 +01:00
//------------------------------------------//
2019-03-18 17:25:44 +01:00
void *malloc(size_t) __attribute__((__malloc__));
void free(void *);
//------------------------------------------//
2019-01-21 15:00:04 +01:00
int rand(void);
void srand(unsigned int);
//------------------------------------------//
char *strerror(int);
char *strsignal(int);
//------------------------------------------//
int toupper(int);
int tolower(int);
static inline int isascii(int __c)
{ return !(__c & ~0xff); }
//------------------------------------------//
extern int __ctype[];
#define _SH(x) (1 << (x))
enum
{
_CT = _SH(0), // control
_PR = _SH(1), // printing
_GR = _SH(2), // graphical
_DX = _SH(3), // hex digit
_DG = _SH(4), // decimal digit
_SP = _SH(5), // space
_BK = _SH(6), // blank
_PT = _SH(7), // punctuation
_AL = _SH(8), // alpha
_UP = _SH(9), // upper alpha
_LW = _SH(10), // lower alpha
};
#define DEC_CTYPE_FUNC(name, flag) \
static inline bool name(int __c) \
{ return isascii(__c) ? !!(__ctype[__c] & flag) : 0; }
DEC_CTYPE_FUNC(iscntrl, _CT);
DEC_CTYPE_FUNC(isprint, _PR);
DEC_CTYPE_FUNC(isgraph, _GR);
DEC_CTYPE_FUNC(isdigit, _DG);
DEC_CTYPE_FUNC(isspace, _SP);
DEC_CTYPE_FUNC(isblank, _BK);
DEC_CTYPE_FUNC(ispunct, _PT);
DEC_CTYPE_FUNC(isalpha, _AL);
DEC_CTYPE_FUNC(isupper, _UP);
DEC_CTYPE_FUNC(islower, _LW);
DEC_CTYPE_FUNC(isxdigit, _DX);
DEC_CTYPE_FUNC(isalnum, (_AL|_DG));
//------------------------------------------//
2019-03-18 14:21:00 +01:00
#ifndef __min_defined
#define __min_defined
static inline int min(int __x, int __y)
{ return __x < __y ? __x : __y; }
#endif
#ifndef __lmin_defined
#define __lmin_defined
static inline int lmin(long __x, long __y)
{ return __x < __y ? __x : __y; }
#endif
#ifndef __max_defined
#define __max_defined
static inline int max(int __x, int __y)
{ return __x > __y ? __x : __y; }
#endif
#ifndef __lmax_defined
#define __lmax_defined
static inline int lmax(long __x, long __y)
{ return __x > __y ? __x : __y; }
#endif
2019-02-16 23:36:33 +01:00
#ifndef __abs_defined
#define __abs_defined
2019-01-21 15:00:04 +01:00
static inline int abs(int __x)
{ return __x < 0 ? -__x : __x; }
2019-01-21 15:00:04 +01:00
#endif
2019-02-16 23:36:33 +01:00
#ifndef __labs_defined
#define __labs_defined
2019-01-21 15:00:04 +01:00
static inline long labs(long __x)
{ return __x < 0 ? -__x : __x; }
2019-01-21 15:00:04 +01:00
#endif
2019-02-16 23:36:33 +01:00
#ifndef __div_defined
#define __div_defined
static inline div_t div(int __x, int __y) {
2019-01-21 15:00:04 +01:00
div_t __res;
__res.quot = __x/__y;
__res.rem = __x%__y;
return __res;
}
#endif
2019-02-16 23:36:33 +01:00
#ifndef __ldiv_defined
#define __ldiv_defined
static inline ldiv_t ldiv(long __x, long __y) {
2019-01-21 15:00:04 +01:00
ldiv_t __res;
__res.quot = __x/__y;
__res.rem = __x%__y;
return __res;
}
#endif
//------------------------------------------//
2019-02-16 23:36:33 +01:00
#ifdef __cplusplus
}
#endif
2019-01-21 15:00:04 +01:00
#endif