libc library
The libc calls twk's packages share on Linux and macOS, bound through
dart:ffi: poll and PollFd, read, write, pipe, close,
ioctl (with fionread), tcgetattr and tcsetattr, calloc and
free, and errno. The core reads the process's terminal with them,
twk_term's Pty drives a pseudo-terminal with them beside calls of its
own, and twk's file watch takes its memory from them.
For the VM on Linux and macOS: a symbol is looked up in the process on
its first call, so importing it costs nothing elsewhere, but calling one
on Windows or the web fails. It is no part of
package:twk_core/twk_core.dart, which compiles for the web too.
How many bytes the terminal on stdin holds, unread:
import 'dart:ffi';
int unread() {
final n = calloc(1, sizeOf<Int>()).cast<Int>();
try {
return ioctl(0, fionread, n.cast()) == 0 ? n.value : 0;
} finally {
free(n.cast());
}
}
Classes
- PollFd
-
struct pollfd, the same on Linux and macOS.
Constants
- eintr → const int
- EINTR: a call interrupted by a signal.
- pollErr → const int
- POLLERR: the descriptor has an error.
- pollHup → const int
- POLLHUP: the other end hung up.
- pollIn → const int
- POLLIN: there is data to read.
- pollNval → const int
- POLLNVAL: the descriptor is not open.
- pollOut → const int
- POLLOUT: a write would not block.
- tcsanow → const int
- TCSANOW, for tcsetattr: the attributes change at once.
Properties
Functions
-
calloc(
int count, int size) → Pointer< Void> -
calloc(3):
countzeroed elements ofsizebytes, ornullptr. -
close(
int fd) → int -
close(2): closes
fd; 0, or -1. -
free(
Pointer< Void> p) → void -
free(3): frees
p, taken from calloc. -
ioctl(
int fd, int request, Pointer< Void> arg) → int -
ioctl(2): the
request(fionread, …) onfdwitharg; -1 on an error. -
pipe(
Pointer< Int> fds) → int -
pipe(2): a pipe, its read end in
fds[0], its write end infds[1]; 0, or -1. -
poll(
Pointer< PollFd> fds, int count, int timeout) → int -
poll(2): waits for the events of
countdescriptors offds, at mosttimeoutmilliseconds (-1 for ever); how many have some, 0 when the time ran out, or -1 (a signal came: EINTR). -
read(
int fd, Pointer< Void> buf, int count) → int -
read(2): reads at most
countbytes offdintobuf; how many, 0 at the end, or -1. A leaf call: read only what is there (after poll, or as many as fionread says), or it blocks the isolate's thread. -
tcgetattr(
int fd, Pointer< Void> termios) → int -
tcgetattr(3): reads the attributes of the terminal
fdintotermios; 0, or -1. -
tcsetattr(
int fd, int when, Pointer< Void> termios) → int -
tcsetattr(3): sets the attributes of the terminal
fdtotermios,when(tcsanow, …) says when; 0, or -1. -
write(
int fd, Pointer< Void> buf, int count) → int -
write(2): writes at most
countbytes ofbuftofd; how many, or -1. A leaf call, like read.