mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
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:
parent
af24c19db3
commit
ccbae7799e
39 changed files with 589 additions and 175 deletions
|
@ -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]);
|
||||
|
|
|
@ -83,7 +83,6 @@ void setlinebuf(FILE *);
|
|||
void setbuf(FILE *, char *);
|
||||
void setbuffer(FILE *, char *, size_t);
|
||||
int setvbuf(FILE *, char *, int, size_t);
|
||||
FILE *popen(const char *, const char *);
|
||||
int pclose(FILE *);
|
||||
char *ctermid(char *);
|
||||
void perror(const char *) relegated;
|
||||
|
@ -94,7 +93,7 @@ int fgetpos(FILE *, fpos_t *) paramsnonnull();
|
|||
int fsetpos(FILE *, const fpos_t *) paramsnonnull();
|
||||
|
||||
int system(const char *);
|
||||
int systemexec(const char *);
|
||||
FILE *popen(const char *, const char *);
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § standard i/o » formatting ─╬─│┼
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "libc/log/log.h"
|
||||
#include "libc/paths.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/cocmd.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
|
@ -62,8 +63,7 @@ int system(const char *cmdline) {
|
|||
sigaction(SIGINT, &saveint, 0);
|
||||
sigaction(SIGQUIT, &savequit, 0);
|
||||
sigprocmask(SIG_SETMASK, &savemask, 0);
|
||||
systemexec(cmdline);
|
||||
_exit(127);
|
||||
_Exit(cocmd(3, (char *[]){"system", "-c", cmdline, 0}));
|
||||
} else if (pid != -1) {
|
||||
while (wait4(pid, &wstatus, 0, 0) == -1) {
|
||||
if (errno != EINTR) {
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/cocmd.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
// Support code for system() and popen().
|
||||
int systemexec(const char *cmdline) {
|
||||
_Exit(cocmd(3, (char *[]){"cocmd.com", "-c", cmdline, 0}));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue