Files
nulsl-libc/src/unistd.c
T
huntedbytheirsandSisyphus b9f8d9bf19 Add libc implementation stubs
Real string core and process teardown; thin read/write/close/getpid/_exit syscall wrappers; the rest follows the stub convention (documented error return, errno = ENOSYS, TODO). syscall.c is the only kernel ABI surface; crt0.S is the static entry point, kept out of libc.a.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
2026-08-30 04:09:45 -04:00

48 lines
993 B
C

/*
* unistd.c — thin wrappers around raw syscalls.
*
* Each function here is a one-liner on purpose: the kernel is the API
* (project guideline #6), and a wrapper that does more than translate
* arguments is a wrapper that can lie. Error translation (kernel -errno
* -> errno) happens inside syscall() itself.
*/
#include <errno.h>
#include <sys/syscall.h>
#include <unistd.h>
ssize_t read(int fd, void *buf, size_t count)
{
return (ssize_t)syscall(SYS_read, fd, buf, count);
}
ssize_t write(int fd, const void *buf, size_t count)
{
return (ssize_t)syscall(SYS_write, fd, buf, count);
}
int close(int fd)
{
return (int)syscall(SYS_close, fd);
}
pid_t getpid(void)
{
return (pid_t)syscall(SYS_getpid);
}
void _exit(int status)
{
syscall(SYS_exit, status);
for (;;)
; /* unreachable */
}
/* Stub: trivially a one-liner once wanted (SYS_unlink = 87 on x86_64). */
int unlink(const char *path)
{
(void)path;
errno = ENOSYS;
return -1;
}