libc: Implement _exit()

Apparently, I implemented _Exit in stdlib.h but forgot to add _exit to unistd.h...
This commit is contained in:
apio 2023-07-11 11:49:10 +02:00
parent 82411789e8
commit 0fed45d1c6
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 15 additions and 1 deletions

View File

@ -3,7 +3,8 @@
#ifndef _BITS_ATTRS_H
#define _BITS_ATTRS_H
#if !defined(_STDLIB_H) && !defined(_STRING_H) && !defined(_ASSERT_H) && !defined(_SETJMP_H) && !defined(_SYS_TIME_H)
#if !defined(_STDLIB_H) && !defined(_UNISTD_H) && !defined(_STRING_H) && !defined(_ASSERT_H) && !defined(_SETJMP_H) && \
!defined(_SYS_TIME_H)
#error "Never include bits/attrs.h directly; use one of the standard library headers."
#endif

View File

@ -7,6 +7,7 @@
#include <stddef.h>
#include <bits/access.h>
#include <bits/attrs.h>
#include <bits/seek.h>
#include <stdint.h>
#include <sys/types.h>
@ -56,6 +57,9 @@ extern "C"
/* Set the current process' effective group ID. */
int setegid(gid_t gid);
/* Set the current process or a child process's process group. */
int setpgid(pid_t pid, pid_t pgid);
/* Change the owner and group of a file. */
int chown(const char* path, uid_t uid, gid_t gid);
@ -86,6 +90,9 @@ extern "C"
/* Call the operating system kernel for a specific service. */
long syscall(long num, ...);
/* Exit the process immediately, without performing any cleanup actions. */
__noreturn void _exit(int status);
/* Sleep for X microseconds. */
int usleep(useconds_t us);

View File

@ -246,6 +246,12 @@ extern "C"
return rc;
}
__noreturn void _exit(int status)
{
syscall(SYS_exit, status);
__builtin_unreachable();
}
int usleep(useconds_t us)
{
long rc = syscall(SYS_usleep, us);