mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 19:36:47 +00:00
46 lines
633 B
C
46 lines
633 B
C
#include <libc/unistd.h>
|
|
#include <libc/stdlib.h>
|
|
#include <libc/ctype.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;
|
|
} |