libc

my libc
git clone git://git.evenfri.pw/libc.git
Log | Files | Refs | README

commit 37152261b048dfc1fc12c0305a0bd87a65df9c75
parent 3601af5dc5a0620cea566e59534f4bfd669fb805
Author: evenfri <evenfri@4plt.ch>
Date:   Mon, 26 Oct 2026 22:52:52 +0800

FEAT: nanosleep and sleep

Diffstat:
Mlibc.h | 3+++
Mmkfile | 2++
Ananosleep.c | 17+++++++++++++++++
Asleep.c | 15+++++++++++++++
4 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/libc.h b/libc.h @@ -105,6 +105,7 @@ struct utimbuf { #define SYS_mmap 9 #define SYS_munmap 11 #define SYS_brk 12 +#define SYS_nanosleep 35 #define SYS_clone 56 #define SYS_fork 57 #define SYS_execve 59 @@ -145,6 +146,8 @@ int execve(const char *path, char *const argv[], char *const envp[]); int execvp(const char *file, char *const argv[]); int fork(void); int waitpid(int pid, int *status, int options); +int nanosleep(const struct timespec *req_time, struct timespec *rem); +unsigned int sleep(unsigned int sec); /* fs */ int mount(const char *src, const char *trg, const char *fstype, ulong_t flags, diff --git a/mkfile b/mkfile @@ -19,6 +19,8 @@ ofiles = start.$o \ execvp.$o \ fork.$o \ waitpid.$o \ + nanosleep.$o \ + sleep.$o \ mount.$o \ mmap.$o \ munmap.$o \ diff --git a/nanosleep.c b/nanosleep.c @@ -0,0 +1,17 @@ +/* + * nanosleep.c - nanosleep system call + * Copyright (C) 2026. All rights reserved. + */ + +#include "libc.h" + +int nanosleep(const struct timespec *req_time, struct timespec *rem) { + long ret = syscall(SYS_nanosleep, (long)req_time, (long)rem, 0, 0, 0, 0); + + if (ret < 0) { + errno = -ret; + return -1; + } + + return ret; +} diff --git a/sleep.c b/sleep.c @@ -0,0 +1,15 @@ +/* + * sleep.c - sleep function + * Copyright (C) 2026. All rights reserved. + */ + +#include "libc.h" + +unsigned int sleep(unsigned int sec) { + struct timespec time; + time.tv_nsec = 0; + time.tv_sec = sec; + + int ret = nanosleep(&time, NULL); + return ret; +}