Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/kernel/src/wasm/posix/termios.zig
1068 views
1
pub fn keepalive() void {}
2
const termios = @cImport(@cInclude("termios.h"));
3
const std = @import("std");
4
const expect = std.testing.expect;
5
const errno = @cImport(@cInclude("errno.h"));
6
7
pub const constants = .{
8
.c_import = termios,
9
.names = [_][:0]const u8{
10
// c_iflag's:
11
"IGNBRK", "BRKINT", "IGNPAR",
12
"PARMRK", "INPCK", "ISTRIP",
13
"INLCR", "IGNCR", "ICRNL",
14
"IXON", "IXANY", "IXOFF",
15
"IMAXBEL", "IUTF8",
16
// c_oflag's:
17
"OPOST",
18
"ONLCR", "OCRNL", "ONOCR",
19
"ONLRET", "OFILL", "OFDEL",
20
// c_cflag's:
21
"CSIZE", "CS5", "CS6",
22
"CS7", "CS8", "CSTOPB",
23
"CREAD", "PARENB", "PARODD",
24
"HUPCL", "CLOCAL",
25
// c_lflag's
26
"ICANON",
27
"ISIG", "ECHO", "ECHOE",
28
"ECHOK", "ECHONL", "NOFLSH",
29
"TOSTOP", "IEXTEN",
30
},
31
};
32
33
34
// ported from zig/lib/libc/wasi/libc-top-half/musl/src/termios/cfsetospeed.c
35
// basically just some pointless implementations that of course don't really matter.
36
pub export fn cfsetospeed(tio: *termios.termios, speed: termios.speed_t) c_int {
37
if ((speed & @bitCast(c_ulong, ~termios.CBAUD)) != 0) {
38
errno.errno = errno.EINVAL;
39
return -1;
40
}
41
tio.c_cflag &= @bitCast(c_ulong, ~termios.CBAUD);
42
tio.c_cflag |= speed;
43
return 0;
44
}
45
46
//int cfsetispeed(struct termios *termios_p, speed_t speed);
47
pub export fn cfsetispeed(tio: *termios.termios, speed: termios.speed_t) c_int {
48
return if (speed != 0) cfsetospeed(tio, speed) else 0;
49
}
50
51
export fn cfgetispeed(tio: *const termios.termios) termios.speed_t {
52
return tio.c_cflag & termios.CBAUD;
53
}
54
55
//int cfsetospeed(struct termios *termios_p, speed_t speed);
56
export fn cfgetospeed(tio: *const termios.termios) termios.speed_t {
57
return cfgetispeed(tio);
58
}
59
60