/* * 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 #include #include 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; }