2007-10-15 11:42:17 +02:00
|
|
|
#ifndef stdlib_h
|
|
|
|
#define stdlib_h
|
|
|
|
#include "kolibrisys.h"
|
|
|
|
|
2008-01-14 20:33:34 +01:00
|
|
|
#define RAND_MAX 65535
|
2016-05-19 14:15:22 +02:00
|
|
|
#ifndef NULL
|
|
|
|
# define NULL ((void*)0)
|
|
|
|
#endif
|
2008-01-14 20:33:34 +01:00
|
|
|
|
2007-10-15 11:42:17 +02:00
|
|
|
#define abs(i) (((i)<0)?(-(i)):(i))
|
2016-05-19 14:15:22 +02:00
|
|
|
#define labs(li) abs(li)
|
2007-10-15 11:42:17 +02:00
|
|
|
|
2018-03-12 21:41:06 +01:00
|
|
|
#define min(a, b) ((a)<(b) ? (a) : (b))
|
|
|
|
#define max(a, b) ((a)>(b) ? (a) : (b))
|
|
|
|
|
|
|
|
|
2007-10-15 11:42:17 +02:00
|
|
|
extern int atoib(char *s,int b);
|
|
|
|
extern int atoi(char *s);
|
2016-06-10 13:10:52 +02:00
|
|
|
extern char *itoab(unsigned int n,char* s,int b);
|
|
|
|
extern char *__itoa(int n,char* s);
|
2007-10-15 11:42:17 +02:00
|
|
|
|
2018-11-01 18:24:22 +01:00
|
|
|
// function using KOS syscalls
|
|
|
|
extern void* stdcall sysmalloc(dword size);
|
|
|
|
extern void stdcall sysfree(void *pointer);
|
|
|
|
extern void* stdcall sysrealloc(void* pointer,dword size);
|
|
|
|
extern void* syscalloc (size_t num, size_t size);
|
|
|
|
|
|
|
|
// suballocator functions
|
|
|
|
extern void* wtmalloc(size_t size);
|
|
|
|
extern void wtfree(void *pointer);
|
|
|
|
extern void* wtrealloc(void* pointer, size_t size);
|
|
|
|
extern void* wtcalloc (size_t num, size_t size);
|
|
|
|
extern int wtmalloc_freelist_check();
|
2018-11-07 18:27:07 +01:00
|
|
|
extern int wtmalloc_poiner_check(void *ptr);
|
|
|
|
extern void wtmalloc_freelist_print();
|
2018-11-01 18:24:22 +01:00
|
|
|
|
|
|
|
#ifdef USESYSALLOC
|
|
|
|
#define malloc(x) sysmalloc(x)
|
|
|
|
#define free(x) sysfree(x)
|
|
|
|
#define realloc(x,y) sysrealloc(x,y)
|
|
|
|
#define calloc(x,y) syscalloc(x,y)
|
|
|
|
#else
|
|
|
|
#define malloc(x) wtmalloc(x)
|
|
|
|
#define free(x) wtfree(x)
|
|
|
|
#define realloc(x,y) wtrealloc(x,y)
|
|
|
|
#define calloc(x,y) wtcalloc(x,y)
|
|
|
|
#endif
|
|
|
|
|
2008-01-14 20:33:34 +01:00
|
|
|
|
|
|
|
extern int rand (void);
|
|
|
|
extern void srand (unsigned int seed);
|
|
|
|
|
2016-05-11 16:53:54 +02:00
|
|
|
double strtod (const char* str, char** endptr);
|
|
|
|
long double strtold (const char* str, char** endptr);
|
|
|
|
float strtof (const char* str, char** endptr);
|
2016-06-10 13:10:52 +02:00
|
|
|
long int strtol (const char* str, char** endptr, int base);
|
|
|
|
#define strtoul(s, ep, b) ((unsigned long int)strtol(s, ep, b))
|
2016-05-11 16:53:54 +02:00
|
|
|
|
|
|
|
|
2018-03-05 18:53:31 +01:00
|
|
|
void exit (int status); /* close console if was initialized, also stay window [finished] when status is error < 0 */
|
2016-05-19 14:15:22 +02:00
|
|
|
#define abort() exit(-1)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int quot;
|
|
|
|
int rem;
|
|
|
|
} div_t;
|
|
|
|
|
|
|
|
typedef div_t ldiv_t;
|
|
|
|
|
|
|
|
div_t div (int numer, int denom);
|
|
|
|
#define ldiv(a, b) div(a, b)
|
|
|
|
#define atol(a) atoi(a)
|
2016-06-10 13:10:52 +02:00
|
|
|
#define atof(a) strtod(a, NULL)
|
|
|
|
|
|
|
|
|
2016-05-19 14:15:22 +02:00
|
|
|
|
|
|
|
#endif
|