2023-04-12 17:53:02 +03:00
|
|
|
#include <BAN/Assert.h>
|
|
|
|
#include <ctype.h>
|
2023-05-06 18:10:38 +03:00
|
|
|
#include <errno.h>
|
2023-04-23 14:32:37 +03:00
|
|
|
#include <stdio.h>
|
2023-04-05 23:58:40 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2023-05-06 18:10:38 +03:00
|
|
|
#include <sys/syscall.h>
|
2023-04-12 17:53:02 +03:00
|
|
|
#include <unistd.h>
|
2023-04-05 23:58:40 +03:00
|
|
|
|
2023-04-19 00:42:00 +03:00
|
|
|
extern "C" void _fini();
|
|
|
|
|
2023-04-05 23:58:40 +03:00
|
|
|
void abort(void)
|
|
|
|
{
|
2023-04-12 17:53:02 +03:00
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
}
|
2023-04-05 23:58:40 +03:00
|
|
|
|
2023-04-12 17:53:02 +03:00
|
|
|
void exit(int status)
|
|
|
|
{
|
2023-04-23 14:32:37 +03:00
|
|
|
fflush(nullptr);
|
2023-04-19 00:42:00 +03:00
|
|
|
_fini();
|
2023-04-12 17:53:02 +03:00
|
|
|
_exit(status);
|
|
|
|
ASSERT_NOT_REACHED();
|
2023-04-05 23:58:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int abs(int val)
|
|
|
|
{
|
|
|
|
return val < 0 ? -val : val;
|
|
|
|
}
|
|
|
|
|
|
|
|
int atexit(void(*)(void))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int atoi(const char* str)
|
|
|
|
{
|
|
|
|
while (isspace(*str))
|
|
|
|
str++;
|
|
|
|
|
|
|
|
bool negative = (*str == '-');
|
|
|
|
|
|
|
|
if (*str == '-' || *str == '+')
|
|
|
|
str++;
|
|
|
|
|
|
|
|
int res = 0;
|
|
|
|
while (isdigit(*str))
|
|
|
|
{
|
|
|
|
res = (res * 10) + (*str - '0');
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return negative ? -res : res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* getenv(const char*)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-05-06 18:10:38 +03:00
|
|
|
void* malloc(size_t bytes)
|
2023-04-05 23:58:40 +03:00
|
|
|
{
|
2023-05-07 01:51:39 +03:00
|
|
|
long res = syscall(SYS_ALLOC, bytes);
|
|
|
|
if (res == -1)
|
2023-05-06 18:10:38 +03:00
|
|
|
return nullptr;
|
2023-05-07 01:51:39 +03:00
|
|
|
return (void*)res;
|
2023-04-05 23:58:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void* calloc(size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
if (nmemb * size < nmemb)
|
|
|
|
return nullptr;
|
|
|
|
void* ptr = malloc(nmemb * size);
|
|
|
|
if (ptr == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
memset(ptr, 0, nmemb * size);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2023-05-07 01:21:50 +03:00
|
|
|
void free(void* ptr)
|
2023-04-05 23:58:40 +03:00
|
|
|
{
|
2023-05-07 01:21:50 +03:00
|
|
|
if (ptr == nullptr)
|
|
|
|
return;
|
|
|
|
syscall(SYS_FREE, ptr);
|
2023-04-05 23:58:40 +03:00
|
|
|
}
|