Improve docs of more system calls

This change also found a few POSIX compliance bugs with errnos. Another
bug was discovered where, on Windows, pread() and pwrite() could modify
the file position in cases where ReadFile() returned an error e.g. when
seeking past the end of file. We also have more tests!
This commit is contained in:
Justine Tunney 2022-10-02 22:14:33 -07:00
parent af24c19db3
commit ccbae7799e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
39 changed files with 589 additions and 175 deletions

View file

@ -19,6 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/runtime/internal.h"
/**
@ -32,16 +33,19 @@
* programs that mix fork() with threads. In that case, apps should
* consider using `sys_getpid().ax` instead to force a system call.
*
* On Linux, and only Linux, the process id is guaranteed to be the same
* as gettid() for the main thread.
* On Linux, and only Linux, getpid() is guaranteed to equal gettid()
* for the main thread.
*
* @return process id (always successful)
* @asyncsignalsafe
* @threadsafe
* @vforksafe
*/
int getpid(void) {
int rc;
if (!__vforked) {
if (IsMetal()) {
rc = 1;
} else if (!__vforked) {
rc = __pid;
} else {
rc = sys_getpid().ax;