commit 81145f1d272b6184f70ce4c393882dc34de3fbe3
parent e54fca23cabb9a58bd8f247a4db19c9dd1ccf03a
Author: Sebastian <sebastian@sebsite.pw>
Date: Tue, 9 May 2023 21:59:23 -0400
unix::tty: rename pty.ha to pty_common.ha
So it isn't shadowed by the OS-specific pty.ha files.
Also used this opportunity to get rid of the license header.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
4 files changed, 49 insertions(+), 51 deletions(-)
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -1467,7 +1467,7 @@ unix_signal() {
unix_tty() {
gen_srcs -plinux unix::tty \
types.ha \
- pty.ha \
+ pty_common.ha \
+linux/isatty.ha \
+linux/open.ha \
+linux/pty.ha \
@@ -1477,7 +1477,7 @@ unix_tty() {
gen_srcs -pfreebsd unix::tty \
types.ha \
- pty.ha \
+ pty_common.ha \
+freebsd/isatty.ha \
+freebsd/open.ha \
+freebsd/pty.ha \
diff --git a/stdlib.mk b/stdlib.mk
@@ -2180,7 +2180,7 @@ $(HARECACHE)/unix/signal/unix_signal-linux.ssa: $(stdlib_unix_signal_linux_srcs)
# unix::tty (+linux)
stdlib_unix_tty_linux_srcs = \
$(STDLIB)/unix/tty/types.ha \
- $(STDLIB)/unix/tty/pty.ha \
+ $(STDLIB)/unix/tty/pty_common.ha \
$(STDLIB)/unix/tty/+linux/isatty.ha \
$(STDLIB)/unix/tty/+linux/open.ha \
$(STDLIB)/unix/tty/+linux/pty.ha \
@@ -2196,7 +2196,7 @@ $(HARECACHE)/unix/tty/unix_tty-linux.ssa: $(stdlib_unix_tty_linux_srcs) $(stdlib
# unix::tty (+freebsd)
stdlib_unix_tty_freebsd_srcs = \
$(STDLIB)/unix/tty/types.ha \
- $(STDLIB)/unix/tty/pty.ha \
+ $(STDLIB)/unix/tty/pty_common.ha \
$(STDLIB)/unix/tty/+freebsd/isatty.ha \
$(STDLIB)/unix/tty/+freebsd/open.ha \
$(STDLIB)/unix/tty/+freebsd/pty.ha \
@@ -4468,7 +4468,7 @@ $(TESTCACHE)/unix/signal/unix_signal-linux.ssa: $(testlib_unix_signal_linux_srcs
# unix::tty (+linux)
testlib_unix_tty_linux_srcs = \
$(STDLIB)/unix/tty/types.ha \
- $(STDLIB)/unix/tty/pty.ha \
+ $(STDLIB)/unix/tty/pty_common.ha \
$(STDLIB)/unix/tty/+linux/isatty.ha \
$(STDLIB)/unix/tty/+linux/open.ha \
$(STDLIB)/unix/tty/+linux/pty.ha \
@@ -4484,7 +4484,7 @@ $(TESTCACHE)/unix/tty/unix_tty-linux.ssa: $(testlib_unix_tty_linux_srcs) $(testl
# unix::tty (+freebsd)
testlib_unix_tty_freebsd_srcs = \
$(STDLIB)/unix/tty/types.ha \
- $(STDLIB)/unix/tty/pty.ha \
+ $(STDLIB)/unix/tty/pty_common.ha \
$(STDLIB)/unix/tty/+freebsd/isatty.ha \
$(STDLIB)/unix/tty/+freebsd/open.ha \
$(STDLIB)/unix/tty/+freebsd/pty.ha \
diff --git a/unix/tty/pty.ha b/unix/tty/pty.ha
@@ -1,45 +0,0 @@
-// License: MPL-2.0
-// (c) 2022 Re Elbertson <citrons@mondecitronne.com>
-use bufio;
-use errors;
-use fmt;
-use fs;
-use io;
-use os;
-use strings;
-
-// Opens an available pseudoterminal and returns the file descriptors of the
-// master and slave.
-export fn openpty() ((io::file, io::file) | fs::error) = {
- let master = open_master()?;
- let slave = match (get_slave(master)) {
- case let e: fs::error =>
- io::close(master)!;
- return e;
- case let s: io::file =>
- yield s;
- };
-
- return (master, slave);
-};
-
-@test fn pty() void = {
- let pty = openpty()!;
- defer io::close(pty.1)!;
- defer io::close(pty.0)!;
-
- assert(fs::exists(os::cwd, ptsname(pty.0)!));
-
- for (let i: u16 = 5; i < 100; i += 1) {
- let sz1 = ttysize { rows = i, columns = i };
- set_winsize(pty.1, sz1)!;
- let sz2 = winsize(pty.1)!;
- assert(sz2.rows == sz1.rows);
- assert(sz2.columns == sz1.columns);
- };
-
- fmt::fprintln(pty.0, "hello, world")!;
- let s = strings::fromutf8(bufio::scanline(pty.1) as []u8)!;
- defer free(s);
- assert(s == "hello, world");
-};
diff --git a/unix/tty/pty_common.ha b/unix/tty/pty_common.ha
@@ -0,0 +1,43 @@
+use bufio;
+use errors;
+use fmt;
+use fs;
+use io;
+use os;
+use strings;
+
+// Opens an available pseudoterminal and returns the file descriptors of the
+// master and slave.
+export fn openpty() ((io::file, io::file) | fs::error) = {
+ let master = open_master()?;
+ let slave = match (get_slave(master)) {
+ case let e: fs::error =>
+ io::close(master)!;
+ return e;
+ case let s: io::file =>
+ yield s;
+ };
+
+ return (master, slave);
+};
+
+@test fn pty() void = {
+ let pty = openpty()!;
+ defer io::close(pty.1)!;
+ defer io::close(pty.0)!;
+
+ assert(fs::exists(os::cwd, ptsname(pty.0)!));
+
+ for (let i: u16 = 5; i < 100; i += 1) {
+ let sz1 = ttysize { rows = i, columns = i };
+ set_winsize(pty.1, sz1)!;
+ let sz2 = winsize(pty.1)!;
+ assert(sz2.rows == sz1.rows);
+ assert(sz2.columns == sz1.columns);
+ };
+
+ fmt::fprintln(pty.0, "hello, world")!;
+ let s = strings::fromutf8(bufio::scanline(pty.1) as []u8)!;
+ defer free(s);
+ assert(s == "hello, world");
+};