4
1
mirror of https://github.com/DragonOS-Community/DragonOS.git synced 2025-06-19 17:26:31 +00:00

🆕 malloc 、printf

This commit is contained in:
fslongjin
2022-05-07 13:46:23 +08:00
parent 78a219b715
commit fd0147e04c
29 changed files with 1587 additions and 56 deletions

45
user/libs/libc/stdlib.c Normal file

@ -0,0 +1,45 @@
#include <libc/unistd.h>
#include <libc/stdlib.h>
int abs(int i)
{
return i < 0 ? -i : i;
}
long labs(long i)
{
return i < 0 ? -i : i;
}
long long llabs(long long i)
{
return i < 0 ? -i : i;
}
int atoi(const char *str)
{
int n = 0, neg = 0;
while (isspace(*str))
{
str++;
}
switch (*str)
{
case '-':
neg = 1;
break;
case '+':
str++;
break;
}
/* Compute n as a negative number to avoid overflow on INT_MIN */
while (isdigit(*str))
{
n = 10 * n - (*str++ - '0');
}
return neg ? n : -n;
}