login c588d6f77f
Patch add abort func (#120)
* 对于除了sigkill以外的信号,也加入队列

* bugfix:libc中,注册信号处理函数时,总是注册sigkill的问题

* 增加getpid系统调用

* 增加了raise、kill、abort
2022-12-19 15:03:44 +08:00

69 lines
1.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <libc/src/ctype.h>
#include <libc/src/stdlib.h>
#include <libc/src/unistd.h>
#include <libsystem/syscall.h>
#include <libc/src/include/signal.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;
}
/**
* @brief 退出进程
*
* @param status
*/
void exit(int status)
{
syscall_invoke(SYS_EXIT, status, 0, 0, 0, 0, 0, 0, 0);
}
/**
* @brief 通过发送SIGABRT从而退出当前进程
*
*/
void abort()
{
// step1设置SIGABRT的处理函数为SIG_DFL
signal(SIGABRT, SIG_DFL);
raise(SIGABRT);
}