mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-14 06:59:10 +00:00
Make terminal ui binaries work well everywhere
Here's some screenshots of an emulator tui program that was compiled on Linux, then scp'd it to Windows, Mac, and FreeBSD. https://justine.storage.googleapis.com/blinkenlights-cmdexe.png https://justine.storage.googleapis.com/blinkenlights-imac.png https://justine.storage.googleapis.com/blinkenlights-freebsd.png https://justine.storage.googleapis.com/blinkenlights-lisp.png How is this even possible that we have a nontrivial ui binary that just works on Mac, Windows, Linux, and BSD? Surely a first ever achievement. Fixed many bugs. Bootstrapped John McCarthy's metacircular evaluator on bare metal in half the size of Altair BASIC (about 2.5kb) and ran it in emulator for fun and profit.
This commit is contained in:
parent
680daf1210
commit
9e3e985ae5
276 changed files with 7026 additions and 3790 deletions
|
@ -1,5 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/typedef/sighandler_t.h"
|
||||
#include "libc/dce.h"
|
||||
|
@ -58,12 +59,10 @@ struct iovec;
|
|||
struct rlimit;
|
||||
struct rusage;
|
||||
struct sigaction;
|
||||
struct siginfo;
|
||||
struct sigset;
|
||||
struct stat;
|
||||
struct sysinfo;
|
||||
struct tms;
|
||||
struct ucontext;
|
||||
struct utsname;
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
|
@ -210,6 +209,7 @@ size_t getfiledescriptorsize(int);
|
|||
ssize_t copy_file_range(int, long *, int, long *, size_t, uint32_t);
|
||||
ssize_t copyfd(int, int64_t *, int, int64_t *, size_t, uint32_t);
|
||||
ssize_t read(int, void *, size_t);
|
||||
ssize_t readansi(int, char *, size_t);
|
||||
ssize_t readlinkat(int, const char *, char *, size_t);
|
||||
ssize_t splice(int, int64_t *, int, int64_t *, size_t, uint32_t);
|
||||
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t);
|
||||
|
|
37
libc/calls/getitimer.c
Normal file
37
libc/calls/getitimer.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Retrieves last setitimer() value, correcting for remaining time.
|
||||
*
|
||||
* @param which can be ITIMER_REAL, ITIMER_VIRTUAL, etc.
|
||||
* @return 0 on success or -1 w/ errno
|
||||
*/
|
||||
int getitimer(int which, struct itimerval *curvalue) {
|
||||
if (!IsWindows()) {
|
||||
return getitimer$sysv(which, curvalue);
|
||||
} else {
|
||||
return setitimer$nt(which, NULL, curvalue);
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ static int mkntcmdline_append(char16_t **p, size_t *i, size_t *n, char16_t c) {
|
|||
* Converts System V argv to Windows-style command line.
|
||||
*
|
||||
* Escaping is performed and it's designed to round-trip with
|
||||
* getdosargv() or getdosargv(). This function does NOT escape
|
||||
* GetDosArgv() or GetDosArgv(). This function does NOT escape
|
||||
* command interpreter syntax, e.g. $VAR (sh), %VAR% (cmd).
|
||||
*
|
||||
* @param argv is an a NULL-terminated array of UTF-8 strings
|
||||
|
|
|
@ -181,6 +181,7 @@ i64 sendfile$sysv(i32, i32, i64 *, u64) hidden;
|
|||
i64 splice$sysv(i32, i64 *, i32, i64 *, u64, u32) hidden;
|
||||
i64 vmsplice$sysv(i32, const struct iovec *, i64, u32) hidden;
|
||||
i64 write$sysv(i32, const void *, u64) hidden;
|
||||
int getitimer$sysv(i32, struct itimerval *) hidden;
|
||||
int setresgid$sysv(uint32_t, uint32_t, uint32_t) hidden;
|
||||
int setresuid$sysv(uint32_t, uint32_t, uint32_t) hidden;
|
||||
u32 getgid$sysv(void) hidden;
|
||||
|
@ -204,6 +205,7 @@ u32 prot2nt(i32, i32) privileged;
|
|||
void __restore_rt() hidden;
|
||||
void __sigenter$xnu(void *, i32, i32, void *, void *) hidden noreturn;
|
||||
int utimensat$xnu(int, const char *, const struct timespec *, int) hidden;
|
||||
int nanosleep$xnu(const struct timespec *, struct timespec *) hidden;
|
||||
void stat2linux(void *) hidden;
|
||||
void xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *,
|
||||
const struct __darwin_ucontext *) hidden noreturn;
|
||||
|
@ -247,6 +249,8 @@ ssize_t read$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
|||
ssize_t write$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
||||
int utimensat$nt(int, const char *, const struct timespec *, int) hidden;
|
||||
int getrusage$nt(int, struct rusage *) hidden;
|
||||
int setitimer$nt(int, const struct itimerval *, struct itimerval *) hidden;
|
||||
int nanosleep$nt(const struct timespec *, struct timespec *) hidden;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § syscalls » windows nt » support ─╬─│┼
|
||||
|
@ -257,6 +261,7 @@ void ntcontext2linux(struct ucontext *, const struct NtContext *) hidden;
|
|||
struct NtOverlapped *offset2overlap(int64_t, struct NtOverlapped *) hidden;
|
||||
bool32 ntsetprivilege(i64, const char16_t *, u32) hidden;
|
||||
bool32 onntconsoleevent$nt(u32) hidden;
|
||||
void onntalarm(void *, uint32_t, uint32_t) hidden;
|
||||
int ntaccesscheck(const char16_t *, u32) paramsnonnull() hidden;
|
||||
i64 ntreturn(u32);
|
||||
i64 winerr(void) nocallback privileged;
|
||||
|
|
|
@ -41,15 +41,23 @@ textwindows int ioctl$tcsets$nt(int ignored, uint64_t request,
|
|||
}
|
||||
inmode &=
|
||||
~(kNtEnableLineInput | kNtEnableEchoInput | kNtEnableProcessedInput);
|
||||
if (tio->c_lflag & ICANON) inmode |= kNtEnableLineInput;
|
||||
if (tio->c_lflag & ECHO) inmode |= kNtEnableEchoInput;
|
||||
if (tio->c_lflag & (IEXTEN | ISIG)) inmode |= kNtEnableProcessedInput;
|
||||
inmode |= kNtEnableWindowInput;
|
||||
if (NtGetVersion() >= kNtVersionWindows10) {
|
||||
inmode |= kNtEnableVirtualTerminalInput;
|
||||
}
|
||||
SetConsoleMode(in, inmode);
|
||||
}
|
||||
if (outok) {
|
||||
SetConsoleMode(out, outmode | kNtEnableProcessedOutput |
|
||||
(NtGetVersion() >= kNtVersionWindows10
|
||||
? kNtEnableVirtualTerminalProcessing
|
||||
: 0));
|
||||
outmode |= kNtEnableWrapAtEolOutput;
|
||||
outmode |= kNtEnableProcessedOutput;
|
||||
if (!(tio->c_oflag & OPOST)) outmode |= kNtDisableNewlineAutoReturn;
|
||||
if (NtGetVersion() >= kNtVersionWindows10) {
|
||||
outmode |= kNtEnableVirtualTerminalProcessing;
|
||||
}
|
||||
SetConsoleMode(out, outmode);
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
|
|
|
@ -28,25 +28,36 @@
|
|||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows int ioctl$tiocgwinsz$nt(int fd, struct winsize *ws) {
|
||||
int i, fds[3];
|
||||
uint32_t mode;
|
||||
struct NtConsoleScreenBufferInfoEx sbinfo;
|
||||
if (!isfdkind(fd, kFdFile)) return ebadf();
|
||||
if (!GetConsoleMode(g_fds.p[fd].handle, &mode)) return enotty();
|
||||
memset(&sbinfo, 0, sizeof(sbinfo));
|
||||
sbinfo.cbSize = sizeof(sbinfo);
|
||||
if (GetConsoleScreenBufferInfoEx(g_fds.p[fd].handle, &sbinfo)) {
|
||||
ws->ws_col = sbinfo.srWindow.Right - sbinfo.srWindow.Left;
|
||||
ws->ws_row = sbinfo.srWindow.Bottom - sbinfo.srWindow.Top;
|
||||
ws->ws_xpixel = 0;
|
||||
ws->ws_ypixel = 0;
|
||||
return 0;
|
||||
} else if (g_ntstartupinfo.dwFlags & kNtStartfUsecountchars) {
|
||||
ws->ws_col = g_ntstartupinfo.dwXCountChars;
|
||||
ws->ws_row = g_ntstartupinfo.dwYCountChars;
|
||||
ws->ws_xpixel = 0;
|
||||
ws->ws_ypixel = 0;
|
||||
return 0;
|
||||
} else {
|
||||
return winerr();
|
||||
fds[0] = fd, fds[1] = 1, fds[2] = 0;
|
||||
for (i = 0; i < ARRAYLEN(fds); ++i) {
|
||||
if (isfdkind(fds[i], kFdFile) || isfdkind(fds[i], kFdConsole)) {
|
||||
if (GetConsoleMode(g_fds.p[fds[i]].handle, &mode)) {
|
||||
memset(&sbinfo, 0, sizeof(sbinfo));
|
||||
sbinfo.cbSize = sizeof(sbinfo);
|
||||
if (GetConsoleScreenBufferInfoEx(g_fds.p[fds[i]].handle, &sbinfo)) {
|
||||
ws->ws_col = sbinfo.srWindow.Right - sbinfo.srWindow.Left + 1;
|
||||
ws->ws_row = sbinfo.srWindow.Bottom - sbinfo.srWindow.Top + 1;
|
||||
ws->ws_xpixel = 0;
|
||||
ws->ws_ypixel = 0;
|
||||
return 0;
|
||||
} else if (g_ntstartupinfo.dwFlags & kNtStartfUsecountchars) {
|
||||
ws->ws_col = g_ntstartupinfo.dwXCountChars;
|
||||
ws->ws_row = g_ntstartupinfo.dwYCountChars;
|
||||
ws->ws_xpixel = 0;
|
||||
ws->ws_ypixel = 0;
|
||||
return 0;
|
||||
} else {
|
||||
winerr();
|
||||
}
|
||||
} else {
|
||||
enotty();
|
||||
}
|
||||
} else {
|
||||
ebadf();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
44
libc/calls/nanosleep-nt.c
Normal file
44
libc/calls/nanosleep-nt.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nt/enum/status.h"
|
||||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/nt/time.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows int nanosleep$nt(const struct timespec *req, struct timespec *rem) {
|
||||
int64_t millis, hectonanos, relasleep;
|
||||
if (rem) memcpy(rem, req, sizeof(*rem));
|
||||
hectonanos = req->tv_sec * 10000000ull + div100int64(req->tv_nsec);
|
||||
hectonanos = MAX(1, hectonanos);
|
||||
relasleep = -hectonanos;
|
||||
if (NtError(NtDelayExecution(true, &relasleep))) {
|
||||
millis = div10000int64(hectonanos);
|
||||
millis = MAX(1, millis);
|
||||
if (SleepEx(millis, true) == kNtWaitIoCompletion) {
|
||||
return eintr();
|
||||
}
|
||||
}
|
||||
if (rem) memset(rem, 0, sizeof(*rem));
|
||||
return 0;
|
||||
}
|
31
libc/calls/nanosleep-xnu.c
Normal file
31
libc/calls/nanosleep-xnu.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/sock/internal.h"
|
||||
|
||||
int nanosleep$xnu(const struct timespec *req, struct timespec *rem) {
|
||||
long millis;
|
||||
millis = div1000int64(req->tv_nsec);
|
||||
millis = MAX(1, millis);
|
||||
return select$sysv(0, 0, 0, 0, &(struct timeval){req->tv_sec, millis});
|
||||
}
|
|
@ -17,48 +17,23 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nt/enum/status.h"
|
||||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/nt/time.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Sleeps for a particular amount of time.
|
||||
*/
|
||||
int nanosleep(const struct timespec *req, struct timespec *rem) {
|
||||
long res, millis, hectonanos;
|
||||
if (!req) return efault();
|
||||
if (!IsWindows()) {
|
||||
if (!IsXnu()) {
|
||||
return nanosleep$sysv(req, rem);
|
||||
} else {
|
||||
return select$sysv(
|
||||
0, 0, 0, 0, /* lool */
|
||||
&(struct timeval){req->tv_sec, div1000int64(req->tv_nsec)});
|
||||
return nanosleep$xnu(req, rem);
|
||||
}
|
||||
} else {
|
||||
if (rem) memcpy(rem, req, sizeof(*rem));
|
||||
if (req->tv_sec && req->tv_nsec) {
|
||||
hectonanos = MAX(1, req->tv_sec * 10000000L + div100int64(req->tv_nsec));
|
||||
} else {
|
||||
hectonanos = 1;
|
||||
}
|
||||
if (NtError(NtDelayExecution(true, &hectonanos))) {
|
||||
millis = div10000int64(hectonanos);
|
||||
res = SleepEx(millis, true);
|
||||
if (res == kNtWaitIoCompletion) return eintr();
|
||||
}
|
||||
if (rem) memset(rem, 0, sizeof(*rem));
|
||||
return 0;
|
||||
return nanosleep$nt(req, rem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,13 +31,7 @@ static struct Now {
|
|||
bool once;
|
||||
uint64_t k0;
|
||||
long double r0, cpn;
|
||||
} now_;
|
||||
|
||||
/**
|
||||
* Returns timestamp without needing system calls.
|
||||
* @note uses microsecond scale fallback on k8 or vm
|
||||
*/
|
||||
long double (*nowl)(void);
|
||||
} g_now;
|
||||
|
||||
static long double GetTimeSample(void) {
|
||||
uint64_t tick1, tick2;
|
||||
|
@ -48,7 +42,7 @@ static long double GetTimeSample(void) {
|
|||
nanosleep(&(struct timespec){0, 100000}, NULL);
|
||||
time2 = dtime(CLOCK_MONOTONIC);
|
||||
tick2 = rdtsc();
|
||||
return (time2 - time1) * 1e9 / (tick2 - tick1);
|
||||
return (time2 - time1) * 1e9 / MAX(1, tick2 - tick1);
|
||||
}
|
||||
|
||||
static long double MeasureNanosPerCycle(void) {
|
||||
|
@ -62,15 +56,15 @@ static long double MeasureNanosPerCycle(void) {
|
|||
}
|
||||
|
||||
static void InitTime(void) {
|
||||
now_.cpn = MeasureNanosPerCycle();
|
||||
now_.r0 = dtime(CLOCK_REALTIME);
|
||||
now_.k0 = rdtsc();
|
||||
now_.once = true;
|
||||
g_now.cpn = MeasureNanosPerCycle();
|
||||
g_now.r0 = dtime(CLOCK_REALTIME);
|
||||
g_now.k0 = rdtsc();
|
||||
g_now.once = true;
|
||||
}
|
||||
|
||||
long double converttickstonanos(uint64_t ticks) {
|
||||
if (!now_.once) InitTime();
|
||||
return ticks * now_.cpn; /* pico scale */
|
||||
if (!g_now.once) InitTime();
|
||||
return ticks * g_now.cpn; /* pico scale */
|
||||
}
|
||||
|
||||
long double converttickstoseconds(uint64_t ticks) {
|
||||
|
@ -83,15 +77,7 @@ long double nowl$sys(void) {
|
|||
|
||||
long double nowl$art(void) {
|
||||
uint64_t ticks;
|
||||
if (!now_.once) InitTime();
|
||||
ticks = unsignedsubtract(rdtsc(), now_.k0);
|
||||
return now_.r0 + converttickstoseconds(ticks);
|
||||
if (!g_now.once) InitTime();
|
||||
ticks = unsignedsubtract(rdtsc(), g_now.k0);
|
||||
return g_now.r0 + converttickstoseconds(ticks);
|
||||
}
|
||||
|
||||
INITIALIZER(301, _init_nowl, {
|
||||
if (X86_HAVE(INVTSC)) {
|
||||
nowl = nowl$art;
|
||||
} else {
|
||||
nowl = nowl$sys;
|
||||
}
|
||||
})
|
||||
|
|
39
libc/calls/nowl.S
Normal file
39
libc/calls/nowl.S
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns timestamp without needing system calls.
|
||||
/
|
||||
/ @return seconds since unix epoch in %st0
|
||||
/ @note uses microsecond scale fallback on k8 or vm
|
||||
.initbss 202,_init_nowl
|
||||
nowl: .quad 0
|
||||
.endobj nowl,globl
|
||||
.previous
|
||||
|
||||
.init.start 202,_init_nowl
|
||||
ezlea nowl$sys,ax
|
||||
ezlea nowl$art,cx
|
||||
testb X86_HAVE(INVTSC)+kCpuids(%rip)
|
||||
cmovnz %rcx,%rax
|
||||
stosq
|
||||
.init.end 202,_init_nowl
|
||||
.source __FILE__
|
31
libc/calls/onntalarm.c
Normal file
31
libc/calls/onntalarm.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
||||
void onntalarm(void *lpArgToCompletionRoutine, uint32_t dwTimerLowValue,
|
||||
uint32_t dwTimerHighValue) {
|
||||
siginfo_t info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.si_signo = SIGALRM;
|
||||
__sigenter(info.si_signo, &info, NULL);
|
||||
}
|
|
@ -37,9 +37,9 @@ textwindows bool32 onntconsoleevent(uint32_t CtrlType) {
|
|||
case kNtCtrlCloseEvent:
|
||||
sig = pushpop(SIGHUP);
|
||||
break;
|
||||
case kNtCtrlLogoffEvent:
|
||||
case kNtCtrlShutdownEvent:
|
||||
sig = pushpop(SIGTERM);
|
||||
case kNtCtrlLogoffEvent: // only received by services so hack hack hack
|
||||
case kNtCtrlShutdownEvent: // only received by services so hack hack hack
|
||||
sig = pushpop(SIGALRM);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -47,7 +48,7 @@ ssize_t pread(int fd, void *buf, size_t size, int64_t offset) {
|
|||
} else if (!IsWindows()) {
|
||||
rc = pread$sysv(fd, buf, size, offset);
|
||||
} else if (isfdkind(fd, kFdFile)) {
|
||||
rc = read$nt(&g_fds.p[fd], buf, size, offset);
|
||||
rc = read$nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset);
|
||||
} else {
|
||||
rc = ebadf();
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) {
|
|||
*/
|
||||
if (!once) {
|
||||
once = true;
|
||||
if (IsLinux() && iovec->iov_len >= __NR_preadv_linux) {
|
||||
if (IsModeDbg() || (IsLinux() && iovec->iov_len >= __NR_preadv_linux)) {
|
||||
/*
|
||||
* Read size is too large to detect older kernels safely without
|
||||
* introducing nontrivial mechanics. We'll try again later.
|
||||
|
|
|
@ -29,7 +29,12 @@
|
|||
#define __NR_pwritev_linux 0x0128
|
||||
|
||||
/**
|
||||
* Writes data from multiple buffers to file descriptor at offset.
|
||||
* Writes data from multiple buffers to offset.
|
||||
*
|
||||
* Please note that it's not an error for a short write to happen. This
|
||||
* can happen in the kernel if EINTR happens after some of the write has
|
||||
* been committed. It can also happen if we need to polyfill this system
|
||||
* call using pwrite().
|
||||
*
|
||||
* @param count is recommended to be 16 or fewer; if it exceeds IOV_MAX
|
||||
* then the extra buffers are simply ignored
|
||||
|
@ -48,7 +53,7 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) {
|
|||
*/
|
||||
if (!once) {
|
||||
once = true;
|
||||
if (IsLinux() && iovec->iov_len >= __NR_pwritev_linux) {
|
||||
if (IsModeDbg() || (IsLinux() && iovec->iov_len >= __NR_pwritev_linux)) {
|
||||
/*
|
||||
* Write size is too large to detect older kernels safely without
|
||||
* introducing nontrivial mechanics. We'll try again later.
|
||||
|
|
124
libc/calls/readansi.c
Normal file
124
libc/calls/readansi.c
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/str/thompike.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Reads single keystroke or control sequence from character device.
|
||||
*
|
||||
* When reading ANSI UTF-8 text streams, characters and control codes
|
||||
* are oftentimes encoded as multi-byte sequences. This function knows
|
||||
* how long each sequence is, so that each read consumes a single thing
|
||||
* from the underlying file descriptor, e.g.
|
||||
*
|
||||
* "a" ALFA
|
||||
* "\316\261" ALPHA
|
||||
* "\033[A" CURSOR UP
|
||||
* "\033[38;5;202m" ORANGERED
|
||||
* "\eOP" PF1
|
||||
*
|
||||
* This routine generalizes to ascii, utf-8, chorded modifier keys,
|
||||
* function keys, color codes, c0/c1 control codes, cursor movement,
|
||||
* mouse movement, etc.
|
||||
*
|
||||
* Userspace buffering isn't required, since ANSI escape sequences and
|
||||
* UTF-8 are decoded without peeking. Noncanonical overlong encodings
|
||||
* can cause the stream to go out of sync. This function recovers such
|
||||
* events by ignoring continuation bytes at the beginning of each read.
|
||||
*
|
||||
* String control sequences, e.g. "\e_hello\e\\" currently are not
|
||||
* tokenized as a single read. Lastly note, this function has limited
|
||||
* support for UNICODE representations of C0/C1 control codes, e.g.
|
||||
*
|
||||
* "\000" NUL
|
||||
* "\300\200" NUL
|
||||
* "\302\233A" CURSOR UP
|
||||
*
|
||||
* @param buf is guaranteed to receive a NUL terminator if size>0
|
||||
* @return number of bytes read (helps differentiate "\0" vs. "")
|
||||
* @see examples/ttyinfo.c
|
||||
* @see ANSI X3.64-1979
|
||||
* @see ISO/IEC 6429
|
||||
* @see FIPS-86
|
||||
* @see ECMA-48
|
||||
*/
|
||||
ssize_t readansi(int fd, char *buf, size_t size) {
|
||||
int i, j;
|
||||
uint8_t c;
|
||||
enum { kAscii, kUtf8, kEsc, kCsi, kSs } t;
|
||||
if (size) buf[0] = 0;
|
||||
for (j = i = 0, t = kAscii;;) {
|
||||
if (i + 2 >= size) return enomem();
|
||||
if (read(fd, &c, 1) != 1) return -1;
|
||||
buf[i++] = c;
|
||||
buf[i] = 0;
|
||||
switch (t) {
|
||||
case kAscii:
|
||||
if (c < 0200) {
|
||||
if (c == '\e') {
|
||||
t = kEsc;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
} else if (c >= 0300) {
|
||||
t = kUtf8;
|
||||
j = ThomPikeLen(c) - 1;
|
||||
}
|
||||
break;
|
||||
case kUtf8:
|
||||
if (!--j) return i;
|
||||
break;
|
||||
case kEsc:
|
||||
switch (c) {
|
||||
case '[':
|
||||
t = kCsi;
|
||||
break;
|
||||
case 'N':
|
||||
case 'O':
|
||||
t = kSs;
|
||||
break;
|
||||
case 0x20 ... 0x2F:
|
||||
break;
|
||||
default:
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
case kCsi:
|
||||
switch (c) {
|
||||
case ':':
|
||||
case ';':
|
||||
case '<':
|
||||
case '=':
|
||||
case '>':
|
||||
case '?':
|
||||
case '0' ... '9':
|
||||
break;
|
||||
default:
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
case kSs:
|
||||
return i;
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
}
|
104
libc/calls/setitimer-nt.c
Normal file
104
libc/calls/setitimer-nt.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/itimerval.h"
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/nt/thread.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/itimer.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Heartbreaking polyfill for SIGALRM on NT.
|
||||
*
|
||||
* Threads are used to trigger the SIGALRM handler, which should
|
||||
* hopefully be an unfancy function like this:
|
||||
*
|
||||
* void OnAlarm(int sig, struct siginfo *si, struct ucontext *uc) {
|
||||
* g_alarmed = true;
|
||||
* }
|
||||
*
|
||||
* This is needed because WIN32 provides no obvious solutions for
|
||||
* interrupting i/o operations on the standard input handle.
|
||||
*/
|
||||
|
||||
static struct ItimerNt {
|
||||
int64_t ith;
|
||||
uint32_t tid;
|
||||
struct itimerval itv;
|
||||
} g_itimernt;
|
||||
|
||||
static uint32_t ItimerWorker(void *arg) {
|
||||
do {
|
||||
if (!WaitForSingleObject(g_itimernt.ith, -1)) {
|
||||
onntalarm(NULL, 0, 0);
|
||||
}
|
||||
} while (g_itimernt.ith && g_itimernt.tid == GetCurrentThreadId());
|
||||
return 0;
|
||||
}
|
||||
|
||||
textwindows int setitimer$nt(int which, const struct itimerval *newvalue,
|
||||
struct itimerval *out_opt_oldvalue) {
|
||||
int32_t period;
|
||||
int64_t ith, duetime;
|
||||
if (which != ITIMER_REAL) return einval();
|
||||
if (newvalue) {
|
||||
if (newvalue->it_value.tv_sec && newvalue->it_value.tv_usec) {
|
||||
if (!(ith = CreateWaitableTimer(NULL, false, NULL))) {
|
||||
return winerr();
|
||||
}
|
||||
duetime = -(newvalue->it_value.tv_sec * HECTONANOSECONDS +
|
||||
newvalue->it_value.tv_usec * 10);
|
||||
period = newvalue->it_value.tv_sec * 1000 +
|
||||
div1000int64(newvalue->it_value.tv_usec);
|
||||
if (!period && newvalue->it_value.tv_usec) period = 1;
|
||||
if (!SetWaitableTimer(ith, &duetime, period, NULL, NULL, false)) {
|
||||
errno = GetLastError();
|
||||
CloseHandle(ith);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ith = 0;
|
||||
}
|
||||
if (g_itimernt.ith) {
|
||||
CloseHandle(g_itimernt.ith);
|
||||
g_itimernt.ith = 0;
|
||||
}
|
||||
} else {
|
||||
ith = 0;
|
||||
}
|
||||
if (out_opt_oldvalue) {
|
||||
memcpy(out_opt_oldvalue, &g_itimernt.itv, sizeof(struct itimerval));
|
||||
}
|
||||
if (ith) {
|
||||
g_itimernt.ith = ith;
|
||||
memcpy(&g_itimernt.itv, newvalue, sizeof(struct itimerval));
|
||||
CloseHandle(
|
||||
CreateThread(NULL, STACKSIZE, ItimerWorker, NULL, 0, &g_itimernt.tid));
|
||||
}
|
||||
return 0;
|
||||
}
|
73
libc/calls/setitimer.c
Normal file
73
libc/calls/setitimer.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/itimerval.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
/**
|
||||
* Schedules delivery of one-shot or intermittent interrupt signal, e.g.
|
||||
*
|
||||
* Raise SIGALRM every 1.5s:
|
||||
*
|
||||
* CHECK_NE(-1, sigaction(SIGALRM,
|
||||
* &(struct sigaction){.sa_sigaction = missingno},
|
||||
* NULL));
|
||||
* CHECK_NE(-1, setitimer(ITIMER_REAL,
|
||||
* &(const struct itimerval){{1, 500000}, {1, 500000}},
|
||||
* NULL));
|
||||
*
|
||||
* Set single-shot 50ms timer callback to interrupt laggy connect():
|
||||
*
|
||||
* CHECK_NE(-1, sigaction(SIGALRM,
|
||||
* &(struct sigaction){.sa_sigaction = missingno,
|
||||
* .sa_flags = SA_RESETHAND},
|
||||
* NULL));
|
||||
* CHECK_NE(-1, setitimer(ITIMER_REAL,
|
||||
* &(const struct itimerval){{0, 0}, {0, 50000}},
|
||||
* NULL));
|
||||
* if (connect(...) == -1 && errno == EINTR) { ... }
|
||||
*
|
||||
* Disarm timer:
|
||||
*
|
||||
* CHECK_NE(-1, setitimer(ITIMER_REAL, &(const struct itimerval){0}, NULL));
|
||||
*
|
||||
* Be sure to check for EINTR on your i/o calls, for best low latency.
|
||||
*
|
||||
* @param which can be ITIMER_REAL, ITIMER_VIRTUAL, etc.
|
||||
* @param newvalue specifies the interval ({0,0} means one-shot) and
|
||||
* duration ({0,0} means disarm) in microseconds ∈ [0,999999] and
|
||||
* if this parameter is NULL, we'll polyfill getitimer() behavior
|
||||
* @param out_opt_old may receive remainder of previous op (if any)
|
||||
* @return 0 on success or -1 w/ errno
|
||||
*/
|
||||
int setitimer(int which, const struct itimerval *newvalue,
|
||||
struct itimerval *out_opt_oldvalue) {
|
||||
if (!IsWindows()) {
|
||||
if (newvalue) {
|
||||
return setitimer$sysv(which, newvalue, out_opt_oldvalue);
|
||||
} else {
|
||||
return getitimer$sysv(which, out_opt_oldvalue);
|
||||
}
|
||||
} else {
|
||||
return setitimer$nt(which, newvalue, out_opt_oldvalue);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
#include "libc/calls/struct/timespec.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
struct stat {
|
||||
struct stat { /* linux abi */
|
||||
int64_t st_dev; /* 0: id of device with file */
|
||||
int64_t st_ino; /* 8: inode number in disk b-tree */
|
||||
int64_t st_nlink; /* 16: hard link count */
|
||||
|
|
27
libc/calls/thunks/onntalarm.S
Normal file
27
libc/calls/thunks/onntalarm.S
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.windows
|
||||
.source __FILE__
|
||||
|
||||
onntalarm$nt:
|
||||
ezlea onntalarm,ax
|
||||
jmp nt2sysv
|
||||
.endfn onntalarm$nt,globl,hidden
|
|
@ -1,10 +1,9 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_TYPEDEF_SIGACTION_F_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_TYPEDEF_SIGACTION_F_H_
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
struct siginfo;
|
||||
struct ucontext;
|
||||
|
||||
typedef void (*sigaction_f)(int, struct siginfo *, struct ucontext *);
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_UCONTEXT_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_UCONTEXT_H_
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaltstack.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
/**
|
||||
* Writes data from multiple buffers.
|
||||
*
|
||||
* Please note that it's not an error for a short write to happen. This
|
||||
* can happen in the kernel if EINTR happens after some of the write has
|
||||
* been committed. It can also happen if we need to polyfill this system
|
||||
* call using write().
|
||||
*
|
||||
* @return number of bytes actually handed off, or -1 w/ errno
|
||||
*/
|
||||
ssize_t writev(int fd, const struct iovec *iov, int iovlen) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue