diff --git a/apps/init.c b/apps/init.c index a23d7f54..b08eac44 100644 --- a/apps/init.c +++ b/apps/init.c @@ -37,12 +37,12 @@ int main() fprintf(stderr, "init is running as PID %d\n", getpid()); - long ret = syscall(SYS_fork); + pid_t ret = fork(); if (ret == 0) { char* argv[] = { "/bin/hello", "--help", NULL }; execv("/bin/hello", argv); } - else { printf("my child is PID %ld!\n", ret); } + else { printf("my child is PID %d!\n", ret); } } diff --git a/libc/include/unistd.h b/libc/include/unistd.h index a12172d9..de69d2e5 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -18,7 +18,8 @@ extern "C" { #endif - pid_t fork(); + /* Create a new process that is a clone of the current one. */ + pid_t fork(void); /* Return the current process' process ID. */ pid_t getpid(void); diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index 2281f72c..23f6e178 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -8,6 +8,12 @@ extern "C" long arch_invoke_syscall(long, uintptr_t, uintptr_t, uintptr_t, uintp extern "C" { + pid_t fork(void) + { + long rc = syscall(SYS_fork); + __errno_return(rc, int); + } + pid_t getpid(void) { return (pid_t)syscall(SYS_getpid);