2022-10-15 12:02:24 +00:00
|
|
|
#include <ctype.h>
|
2022-10-02 16:10:53 +00:00
|
|
|
#include <luna.h>
|
2022-10-01 18:59:22 +00:00
|
|
|
#include <stdlib.h>
|
2022-10-02 15:02:15 +00:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-10-15 12:02:24 +00:00
|
|
|
template <typename T> T string_to_integer_type(const char* str)
|
|
|
|
{
|
|
|
|
bool neg = false;
|
|
|
|
T val = 0;
|
|
|
|
|
|
|
|
switch (*str)
|
|
|
|
{
|
|
|
|
case '-':
|
|
|
|
neg = true;
|
|
|
|
str++;
|
|
|
|
break;
|
|
|
|
case '+': str++; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (isdigit(*str)) { val = (10 * val) + (*str++ - '0'); }
|
|
|
|
|
|
|
|
return (neg ? -val : val);
|
|
|
|
}
|
|
|
|
|
2022-10-01 18:59:22 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2022-10-15 07:52:37 +00:00
|
|
|
__lc_noreturn void abort()
|
2022-10-01 18:59:22 +00:00
|
|
|
{
|
2022-10-15 12:02:10 +00:00
|
|
|
_Exit(-1);
|
2022-10-01 18:59:22 +00:00
|
|
|
}
|
2022-10-12 09:30:21 +00:00
|
|
|
|
2022-10-15 12:02:24 +00:00
|
|
|
int atoi(const char* str)
|
|
|
|
{
|
|
|
|
return string_to_integer_type<int>(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
long atol(const char* str)
|
|
|
|
{
|
|
|
|
return string_to_integer_type<long>(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
long long atoll(const char* str)
|
2022-10-01 18:59:22 +00:00
|
|
|
{
|
2022-10-15 12:02:24 +00:00
|
|
|
return string_to_integer_type<long long>(str);
|
2022-10-01 18:59:22 +00:00
|
|
|
}
|
2022-10-12 09:30:21 +00:00
|
|
|
|
2022-10-01 18:59:22 +00:00
|
|
|
char* getenv(const char*)
|
|
|
|
{
|
2022-10-02 16:10:53 +00:00
|
|
|
NOT_IMPLEMENTED("getenv");
|
2022-10-01 18:59:22 +00:00
|
|
|
}
|
2022-10-15 12:02:10 +00:00
|
|
|
|
|
|
|
__lc_noreturn void _Exit(int status)
|
|
|
|
{
|
|
|
|
syscall(SYS_exit, status);
|
|
|
|
__lc_unreachable();
|
|
|
|
}
|
2022-10-01 18:59:22 +00:00
|
|
|
}
|