raz / commit 414ba15e

commit
414ba15e434e6a5e792190f607b48ffbd177d3e2
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
147c815d
Files.write: close with closeChecked, so a late write error is seen

patch · log

2 files changed, +4 -4

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

@@ -872,7 +872,7 @@
872872 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 *)
875-proc write*(path, data: []U8): BOOL; (* the file made to hold data *)
875+proc write*(path, data: []U8): BOOL; (* the file made to hold data; false if it or its close failed *)
876876
877877 module Opt;
878878 type

lib/Files.raz (history) modified +3 -3

@@ -38,7 +38,8 @@
3838 return load(path, b) = 0;
3939 end;
4040
41-(* Makes the file at path hold data; false if it can't be written. *)
41+(* Makes the file at path hold data; false if it can't be written, or
42+ the close, where a late write error shows, fails. *)
4243 proc write*(path, data: []U8): BOOL;
4344 var fd, n, at: INT;
4445 begin
@@ -51,8 +52,7 @@
5152 elsif n # Sys.errIntr then Sys.close(fd); return false; (* a signal broke in: write again *)
5253 end;
5354 end;
54- Sys.close(fd);
55- return true;
55+ return Sys.closeChecked(fd) = 0; (* a write error may come only at the close *)
5656 end;
5757
5858 (* The module's test. *)