lib: rename stdlib surface to Hare names; add endian/math
Sweeping rename so the lib/ surface mirrors Hare's stdlib spellings. - ascii: rune-taking predicates; ishex -> isxdigit - bufio: rinit -> init; take1/takeline -> readbyte/readline - bytes: indexsub -> index - encoding/utf8: runelen -> runesz - errors: eEOF/eShortRead/... -> eof/underread/... - fmt: errln -> errorln; println/fprintln return i64 - os: readfull/writefull -> readall/writeall; unlink -> remove - path: isabs -> abs; drop lastindex (now strings.rbyteindex) - strconv: u64toa/i64toa -> u64tos/i64tos; parse64/parseu64 -> stoi64/stou64 - strings: drop len/isempty; equal -> compare; indexbyte -> byteindex; +rbyteindex - types: drop numeric helpers (moved to math) - new lib/endian (htonu16/ntohu16), lib/math (absi32/absi64) - net: drop htons (use endian.htonu16) Callers in selfhost/, lib/ww/, cmd/w6c/cgen.c, and test/wcc/700_e2e.c updated to match.
This commit is contained in:
17
lib/os/os.ww
17
lib/os/os.ww
@@ -119,9 +119,11 @@ export fn filesize(fd: i32) i64 = {
|
||||
return end;
|
||||
};
|
||||
|
||||
// readfull — keep reading until `n` bytes have arrived or the fd
|
||||
// readall — keep reading until `n` bytes have arrived or the fd
|
||||
// closes early. Returns bytes read (0..=n) or -1 on read error.
|
||||
export fn readfull(fd: i32, buf: *u8, n: u64) i64 = {
|
||||
// Hare name (io::readall); the buffer is caller-supplied, matching
|
||||
// the Plan 9 subset convention.
|
||||
export fn readall(fd: i32, buf: *u8, n: u64) i64 = {
|
||||
let got: u64 = 0u64;
|
||||
for (got < n) {
|
||||
let r: i64 = read(fd, buf + got, n - got);
|
||||
@@ -132,9 +134,10 @@ export fn readfull(fd: i32, buf: *u8, n: u64) i64 = {
|
||||
return got: i64;
|
||||
};
|
||||
|
||||
// writefull — keep writing until `n` bytes have been accepted or the
|
||||
// fd refuses progress. Returns bytes written or -1.
|
||||
export fn writefull(fd: i32, buf: *u8, n: u64) i64 = {
|
||||
// writeall — keep writing until `n` bytes have been accepted or the
|
||||
// fd refuses progress. Returns bytes written or -1. Hare name
|
||||
// (io::writeall).
|
||||
export fn writeall(fd: i32, buf: *u8, n: u64) i64 = {
|
||||
let sent: u64 = 0u64;
|
||||
for (sent < n) {
|
||||
let r: i64 = write(fd, buf + sent, n - sent);
|
||||
@@ -153,8 +156,8 @@ export fn access(path: *u8, mode: i32) i32 = {
|
||||
return syscall2(SYS_ACCESS, path: i64, mode: i64): i32;
|
||||
};
|
||||
|
||||
// unlink(2).
|
||||
export fn unlink(path: *u8) i32 = {
|
||||
// remove — unlink(2). Hare name; the underlying syscall is unlink(2).
|
||||
export fn remove(path: *u8) i32 = {
|
||||
return syscall1(SYS_UNLINK, path: i64): i32;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user