1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! The Darwin-specific half of the unix backend — macOS on `x86_64` and on
//! `aarch64` (Apple Silicon), which are identical at this level.
//!
//! Two items, because two items is all Linux and Darwin disagree about once the
//! constant tables (`abi.rs`) and the struct layouts (`layout.rs`) are factored
//! out: which `struct termios` to pass, and how to reach `errno`.
//!
//! Authority: `xnu/bsd/sys/termios.h` for the layout — `tcflag_t` and `speed_t`
//! are `unsigned long` (8 bytes on both Apple architectures), `NCCS` is 20,
//! there is no `c_line`, and `sizeof(struct termios)` is 72 — and
//! `<sys/errno.h>`'s `#define errno (*__error())` for the accessor. Note that
//! `__error()` is a *different symbol* from Linux's `__errno_location()`;
//! nothing warns you, the link simply fails, which is the good case.
//!
//! Everything else this backend needs is in libSystem, which every Apple target
//! links by default (rustc passes `-lSystem` for `*-apple-darwin`), so
//! `tcgetattr`, `tcsetattr`, `ioctl`, `read`, `write`, `isatty`, `open`,
//! `close` and `signal` need no `#[link]` attribute. Deliberately so: Apple
//! does not support statically linking libSystem, and naming it explicitly
//! would only invite someone to try.
use crateHOST_ABI;
use crate;
/// The `struct termios` this target's libc expects.
pub type RawTermios = DarwinTermios;
// A Linux table paired with a Darwin struct would put VMIN at c_cc[6] — inside
// the 20-slot array, so no bounds error, just VREPRINT set to 0 and VMIN left
// at whatever the terminal had (usually 1), which blocks the event loop
// forever instead of ticking every 100 ms.
const _: = assert!;
const _: = assert!;
// _IOR('t', 104, struct winsize), computed by `abi::bsd_ior` — not Linux's
// 0x5413, which on Darwin would be a request in group 0x54 ('T') that no tty
// driver implements.
const _: = assert!;
// `tcflag_t` is 8 bytes here, so the flag words are used at full width; this
// pins the four values that differ from Linux and would otherwise clear the
// wrong bits silently.
const _: = assert!;
const _: = assert!;
const _: = assert!;
extern "C"
/// The current thread's `errno`.