raz / commit 147c815d

commit
147c815d6806d1a624cc3e57c4200c65314ec521
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
5b96aba7
Files.arg: empty past the arguments, not a nil pointer

patch · log

2 files changed, +5 -2

doc/raz-lib.md (history) modified +1 -1

@@ -869,7 +869,7 @@
869869
870870 ```
871871 module Files;
872-proc arg*(i: INT): []U8; (* argument i; 0 is the program's name *)
872+proc arg*(i: INT): []U8; (* argument i; 0 is the program's name; "" if there is none *)
873873 proc read*(path: []U8; var b: Buf.Buf): BOOL; (* the whole file added to b *)
874874 proc load*(path: []U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)
875875 proc write*(path, data: []U8): BOOL; (* the file made to hold data *)

lib/Files.raz (history) modified +4 -1

@@ -3,10 +3,12 @@
33 module Files;
44 import Sys, Buf, Heap, Rt;
55
6-(* Argument i, a C string, as a slice. *)
6+(* Argument i, a C string, as a slice; empty if there is no argument i,
7+ as for i below 0 or from ARGC() on. *)
78 proc arg*(i: INT): []U8;
89 var s: ^U8; n: INT;
910 begin
11+ if (i < 0) or (i >= ARGC()) then return ""; end;
1012 s := ARGV()[i];
1113 n := 0;
1214 while s[n] # 0 do INC(n); end;
@@ -65,6 +67,7 @@
6567 if load("/tmp/raz-files-test", b) # Sys.errNoEntry then Rt.stop("Files.load: no such file"); end;
6668 if load("/", b) # -21 then Rt.stop("Files.load: a directory"); end;
6769 if read("/", b) or (b.len # 6) then Rt.stop("Files.read: a directory"); end;
70+ if (LEN(arg(ARGC())) # 0) or (LEN(arg(-1)) # 0) then Rt.stop("Files.arg: past the arguments"); end;
6871 Buf.done(b);
6972 end;
7073