code wiki / _hdl_build / nx_gate_read.nx

nx_gate_read.nx source

↩ module page · 8 lines · 472 B

1import "nx_syscalls.nx" 2// consolidated file-read helper (funcmine g_read group, byte-identical copies -> 1 lib; rule 15 DRY). Behaviorally-verified migration. 3func g_read(path: *u8, buf: *u8, cap: i64) -> i64 { 4 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } 5 var tot: i64 = 0; var r: i64 = 1 6 while r > 0 { let dst: *u8 = ((buf as i64) + tot) as *u8; r = sys_read(fd, dst, cap - tot); if r > 0 { tot = tot + r } } 7 sys_close(fd); return tot 8}