I have the following code
const std = @import("std");
const stdio = @cImport({
@cInclude("stdio.h");
});
const ioctl = @cImport({
@cInclude("sys/ioctl.h");
@cInclude("stdio.h");
@cInclude("unistd.h");
@cInclude("errno.h");
@cInclude("termios.h");
});
pub fn main() !void {
var t = ioctl.termios {
};
const is_terminal = ioctl.ioctl(0, ioctl.TIOCGETA, t);
if (is_terminal == 0) {
t.c_iflag &= @intCast(@as(c_long, @intCast(~(ioctl.IGNBRK
| ioctl.BRKINT
| ioctl.PARMRK
| ioctl.ISTRIP
| ioctl.INLCR
| ioctl.IGNCR
| ioctl.ICRNL
| ioctl.IXON))));
t.c_oflag &= ~ioctl.OPOST;
t.c_lflag &= ~(ioctl.ECHO | ioctl.ECHONL | ioctl.ICANON | ioctl.ISIG | ioctl.IEXTEN);
t.c_cflag &= ~(ioctl.CSIZE | ioctl.PARENB);
t.c_cflag |= ioctl.CS8;
t.c_cc[ioctl.VMIN] = 1;
t.c_cc[ioctl.VTIME] = 0;
ioctl.ioctl(0, ioctl.TIOCSETA, t);
}
std.debug.print("Hello {any}.", .{ is_terminal });
}
The goal is to put the terminal into raw mode. Problem is: I can't make zig accept the code. I've done the same call in Java through jextract generated code so I know its right (or should be). Is there something I am missing?
main.zig:46:31: error: type 'c_ulong' cannot represent integer value '-1004'
t.c_iflag &= @intCast(@as(c_long, @intCast(~(ioctl.IGNBRK
^~~
referenced by:
main: /Users/emccue/Library/zig/0.15.0-dev.375+8f8f37fb0/lib/std/start.zig:671:37
comptime: /Users/emccue/Library/zig/0.15.0-dev.375+8f8f37fb0/lib/std/start.zig:58:30
2 reference(s) hidden; use '-freference-trace=4' to see all references