commit 7ed35bfbb13dc9a9abf45396bee934f317fe4f70
parent 045f309618a09c836b54662ee1bcf8239b365f61
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 10 Oct 2022 19:55:25 +0200
Revert unix buffered I/O changes
Does not work on FreeBSD and needs more work regardless.
This reverts commit fb661e20b1fa3cb8d5a6d7d5e8fd39d2d7cfd588.
Diffstat:
4 files changed, 5 insertions(+), 62 deletions(-)
diff --git a/unix/hosts/lookup.ha b/unix/hosts/lookup.ha
@@ -15,16 +15,10 @@ export fn lookup(name: str) []ip::addr = {
// XXX: Would be cool to have meaningful error handling(?)
const file = os::open(PATH)!;
defer io::close(file)!;
- return lookupio(name, file);
-};
-
-fn lookupio(name: str, src: io::handle) []ip::addr = {
- let buffer: [os::BUFSIZ]u8 = [0...];
- const buf = bufio::buffered(src, buffer, []);
let addrs: []ip::addr = [];
for (true) {
- const line = match (bufio::scanline(&buf)) {
+ const line = match (bufio::scanline(file)) {
case io::EOF =>
break;
case let line: []u8 =>
@@ -61,20 +55,3 @@ fn lookupio(name: str, src: io::handle) []ip::addr = {
};
return addrs;
};
-
-@test fn lookup() void = {
- let buf = bufio::fixed(strings::toutf8(
- "127.0.0.1 localhost\n"
- "\n"
- "# The following lines are desirable for IPv6 capable hosts\n"
- "::1 ip6-localhost ip6-loopback\n"
- "fe00::0 ip6-localnet\n"
- "ff00::0 ip6-mcastprefix\n"
- "ff02::1 ip6-allnodes\n"
- "ff02::2 ip6-allrouters\n"), io::mode::READ);
- const ips = lookupio("localhost", &buf);
- assert(len(ips) == 1);
- const got = ips[0];
- const want: ip::addr4 = [127, 0, 0, 1];
- assert(ip::equal(got, want));
-};
diff --git a/unix/passwd/group.ha b/unix/passwd/group.ha
@@ -77,11 +77,9 @@ export fn getgroup(name: str) (grent | void) = {
abort("Unable to open /etc/group");
};
defer io::close(file)!;
- let buffer: [os::BUFSIZ]u8 = [0...];
- const buf = bufio::buffered(file, buffer, []);
-
+
for (true) {
- let ent = match (nextgr(&buf)) {
+ let ent = match (nextgr(file)) {
case let e: grent =>
yield e;
case io::EOF =>
@@ -129,11 +127,6 @@ export fn getgid(gid: uint) (grent | void) = {
};
};
-@test fn getgroup() void = {
- const g = getgroup("root") as grent;
- assert(g.name == "root");
-};
-
@test fn nextgr() void = {
let buf = bufio::fixed(strings::toutf8(
"root:x:0:root\n"
diff --git a/unix/passwd/passwd.ha b/unix/passwd/passwd.ha
@@ -96,11 +96,9 @@ export fn getuser(username: str) (pwent | void) = {
abort("Can't open /etc/passwd");
};
defer io::close(file)!;
- let buffer: [os::BUFSIZ]u8 = [0...];
- const buf = bufio::buffered(file, buffer, []);
for (true) {
- let ent = match (nextpw(&buf)) {
+ let ent = match (nextpw(file)) {
case let e: pwent =>
yield e;
case io::EOF =>
@@ -151,11 +149,6 @@ export fn getuid(uid: uint) (pwent | void) = {
};
};
-@test fn getuser() void = {
- const u = getuser("root") as pwent;
- assert(u.username == "root");
-};
-
@test fn nextpw() void = {
let buf = bufio::fixed(strings::toutf8(
"sircmpwn:x:1000:1000:sircmpwn's comment:/home/sircmpwn:/bin/mrsh\n"
diff --git a/unix/resolvconf/load.ha b/unix/resolvconf/load.ha
@@ -25,15 +25,9 @@ export fn load() []ip::addr = {
const file = os::open(PATH)!;
defer io::close(file)!;
- return loadio(file);
-};
-
-fn loadio(src: io::handle) []ip::addr = {
- let buffer: [os::BUFSIZ]u8 = [0...];
- const buf = bufio::buffered(src, buffer, []);
for (true) {
- const line = match (bufio::scanline(&buf)) {
+ const line = match (bufio::scanline(file)) {
case io::EOF =>
break;
case let line: []u8 =>
@@ -68,17 +62,3 @@ fn loadio(src: io::handle) []ip::addr = {
return cache;
};
-
-@test fn load() void = {
- let buf = bufio::fixed(strings::toutf8(
- "# comment\n"
- "nameserver 127.0.0.1\n"
- "options edns0 trust-ad\n"
- "search home"), io::mode::READ);
-
- const ips = loadio(&buf);
- assert(len(ips) == 1);
- const got = ips[0];
- const want: ip::addr4 = [127, 0, 0, 1];
- assert(ip::equal(got, want));
-};