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

@ -20,6 +20,7 @@
#include "libc/errno.h"
#include "libc/paths.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/cocmd.internal.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/f.h"
@ -50,7 +51,7 @@ FILE *popen(const char *cmdline, const char *mode) {
} else if ((flags & O_ACCMODE) == O_WRONLY) {
dir = 1;
} else {
errno = EINVAL;
einval();
return NULL;
}
if (pipe(pipefds) == -1) return NULL;
@ -59,8 +60,7 @@ FILE *popen(const char *cmdline, const char *mode) {
switch ((pid = fork())) {
case 0:
dup2(pipefds[!dir], !dir);
systemexec(cmdline);
_exit(127);
_Exit(cocmd(3, (char *[]){"popen", "-c", cmdline, 0}));
default:
f->pid = pid;
close(pipefds[!dir]);