diff --git a/Userspace/libc/include/signal.h b/Userspace/libc/include/signal.h index 8c488ffe..7d1bfb34 100644 --- a/Userspace/libc/include/signal.h +++ b/Userspace/libc/include/signal.h @@ -197,14 +197,14 @@ extern "C" int pthread_sigmask(int, const sigset_t *restrict, sigset_t *restrict); int raise(int); int sig2str(int, char *); - int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict); + int sigaction(int sig, const struct sigaction *restrict act, struct sigaction *restrict oact); int sigaddset(sigset_t *, int); int sigaltstack(const stack_t *restrict, stack_t *restrict); int sigdelset(sigset_t *, int); - int sigemptyset(sigset_t *); + int sigemptyset(sigset_t *set); int sigfillset(sigset_t *); int sigismember(const sigset_t *, int); - void (*signal(int, void (*)(int)))(int); + void (*signal(int sig, void (*func)(int)))(int); int sigpending(sigset_t *); int sigprocmask(int, const sigset_t *restrict, sigset_t *restrict); int sigqueue(pid_t, int, union sigval); diff --git a/Userspace/libc/include/string.h b/Userspace/libc/include/string.h index ac6578c3..7b50f55c 100644 --- a/Userspace/libc/include/string.h +++ b/Userspace/libc/include/string.h @@ -41,7 +41,7 @@ extern "C" int strcoll(const char *, const char *); int strcoll_l(const char *, const char *, locale_t); char *strcpy(char *restrict, const char *restrict); - size_t strcspn(const char *, const char *); + size_t strcspn(const char *s1, const char *s2); char *strdup(const char *); char *strerror(int); char *strerror_l(int, locale_t); diff --git a/Userspace/libc/src/std/signal.c b/Userspace/libc/src/std/signal.c index 943a3a0c..eb857bd0 100644 --- a/Userspace/libc/src/std/signal.c +++ b/Userspace/libc/src/std/signal.c @@ -16,6 +16,8 @@ */ #include +#include +#include export int kill(pid_t pid, int sig) { @@ -29,14 +31,65 @@ export int pthread_kill(pthread_t, int); export int pthread_sigmask(int, const sigset_t *restrict, sigset_t *restrict); export int raise(int); export int sig2str(int, char *); -export int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict); + +export int sigaction(int sig, const struct sigaction *restrict act, struct sigaction *restrict oact) +{ + if (sig == SIGKILL || sig == SIGSTOP) + { + errno = EINVAL; + return -1; + } + + if (oact != NULL) + { + printf("sigaction() is unimplemented\n"); + // if (syscall3(SYS_RT_SIGACTION, sig, NULL, oact, sizeof(sigset_t)) < 0) + return -1; + } + + if (act != NULL) + { + printf("sigaction() is unimplemented\n"); + // if (syscall3(SYS_RT_SIGACTION, sig, act, NULL, sizeof(sigset_t)) < 0) + return -1; + } + + return 0; +} + export int sigaddset(sigset_t *, int); export int sigaltstack(const stack_t *restrict, stack_t *restrict); export int sigdelset(sigset_t *, int); -export int sigemptyset(sigset_t *); + +export int sigemptyset(sigset_t *set) +{ + if (set == NULL) + { + errno = EINVAL; + return -1; + } + + *set = 0; + return 0; +} + export int sigfillset(sigset_t *); export int sigismember(const sigset_t *, int); -export void (*signal(int, void (*)(int)))(int); + +export void (*signal(int sig, void (*func)(int)))(int) +{ + struct sigaction act, oact; + + act.sa_handler = func; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + + if (sigaction(sig, &act, &oact) < 0) + return SIG_ERR; + + return oact.sa_handler; +} + export int sigpending(sigset_t *); export int sigprocmask(int, const sigset_t *restrict, sigset_t *restrict); export int sigqueue(pid_t, int, union sigval); diff --git a/Userspace/libc/src/std/string.c b/Userspace/libc/src/std/string.c index 0307adca..5c1638fc 100644 --- a/Userspace/libc/src/std/string.c +++ b/Userspace/libc/src/std/string.c @@ -75,7 +75,24 @@ export int strcmp(const char *s1, const char *s2) export int strcoll(const char *, const char *); export int strcoll_l(const char *, const char *, locale_t); export char *strcpy(char *restrict, const char *restrict); -export size_t strcspn(const char *, const char *); + +export size_t strcspn(const char *s1, const char *s2) +{ + const char *p = s1; + const char *spanp; + char c, sc; + + while ((c = *p++) != 0) + { + for (spanp = s2; (sc = *spanp++) != 0;) + { + if (sc == c) + return p - 1 - s1; + } + } + return p - 1 - s1; +} + export char *strdup(const char *); export char *strerror(int); export char *strerror_l(int, locale_t);