hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit dacf8fdbe8243ba42cd4e315d15e1b4293b087e2
parent 423f4bb77221c4eddedec84554eca9b036abef3c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 23 Jun 2021 17:58:45 -0400

unix::hosts, resolvconf: fix minor issues

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Munix/hosts/lookup.ha | 10++++++----
Munix/resolvconf/load.ha | 2+-
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/unix/hosts/lookup.ha b/unix/hosts/lookup.ha @@ -9,19 +9,20 @@ def path: str = "/etc/hosts"; // Looks up a host from /etc/hosts. Aborts the program if the file does not // exist, is written in an invalid format, or if any other error occurs. -export fn lookup(name: str) (ip::addr | void) = { +export fn lookup(name: str) []ip::addr = { // XXX: Would be cool if we could do this without allocating anything - // XXX: Would be cool to add caching + // XXX: Would be cool to have meaningful error handling(?) const file = os::open(path)!; defer io::close(file); + let addrs: []ip::addr = []; for (true) { const line = match (bufio::scanline(file)) { io::EOF => break, line: []u8 => line, }; defer free(line); - if (line[0] == '#': u32: u8 || len(line) == 0) { + if (len(line) == 0 || line[0] == '#': u32: u8) { continue; }; @@ -43,8 +44,9 @@ export fn lookup(name: str) (ip::addr | void) = { defer free(tok); if (strings::fromutf8(tok) == name) { - return addr; + append(addrs, addr); }; }; }; + return addrs; }; diff --git a/unix/resolvconf/load.ha b/unix/resolvconf/load.ha @@ -31,7 +31,7 @@ export fn load() []ip::addr = { line: []u8 => line, }; defer free(line); - if (line[0] == '#': u32: u8 || len(line) == 0) { + if (len(line) == 0 || line[0] == '#': u32: u8) { continue; };