From 147c815d6806d1a624cc3e57c4200c65314ec521 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:04:51 +0100 Subject: [PATCH] Files.arg: empty past the arguments, not a nil pointer --- diff --git a/doc/raz-lib.md b/doc/raz-lib.md index f9c5b53..5951b23 100644 --- a/doc/raz-lib.md +++ b/doc/raz-lib.md @@ -869,7 +869,7 @@ ``` module Files; -proc arg*(i: INT): []U8; (* argument i; 0 is the program's name *) +proc arg*(i: INT): []U8; (* argument i; 0 is the program's name; "" if there is none *) proc read*(path: []U8; var b: Buf.Buf): BOOL; (* the whole file added to b *) proc load*(path: []U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *) proc write*(path, data: []U8): BOOL; (* the file made to hold data *) diff --git a/lib/Files.raz b/lib/Files.raz index 7ad89d6..8be54ac 100644 --- a/lib/Files.raz +++ b/lib/Files.raz @@ -3,10 +3,12 @@ module Files; import Sys, Buf, Heap, Rt; -(* Argument i, a C string, as a slice. *) +(* Argument i, a C string, as a slice; empty if there is no argument i, + as for i below 0 or from ARGC() on. *) proc arg*(i: INT): []U8; var s: ^U8; n: INT; begin + if (i < 0) or (i >= ARGC()) then return ""; end; s := ARGV()[i]; n := 0; while s[n] # 0 do INC(n); end; @@ -65,6 +67,7 @@ if load("/tmp/raz-files-test", b) # Sys.errNoEntry then Rt.stop("Files.load: no such file"); end; if load("/", b) # -21 then Rt.stop("Files.load: a directory"); end; if read("/", b) or (b.len # 6) then Rt.stop("Files.read: a directory"); end; + if (LEN(arg(ARGC())) # 0) or (LEN(arg(-1)) # 0) then Rt.stop("Files.arg: past the arguments"); end; Buf.done(b); end;