From 414ba15e434e6a5e792190f607b48ffbd177d3e2 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:04:56 +0100 Subject: [PATCH] Files.write: close with closeChecked, so a late write error is seen --- diff --git a/doc/raz-lib.md b/doc/raz-lib.md index 5951b23..7f3a011 100644 --- a/doc/raz-lib.md +++ b/doc/raz-lib.md @@ -872,7 +872,7 @@ 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 *) +proc write*(path, data: []U8): BOOL; (* the file made to hold data; false if it or its close failed *) module Opt; type diff --git a/lib/Files.raz b/lib/Files.raz index 8be54ac..57e2f0f 100644 --- a/lib/Files.raz +++ b/lib/Files.raz @@ -38,7 +38,8 @@ return load(path, b) = 0; end; -(* Makes the file at path hold data; false if it can't be written. *) +(* Makes the file at path hold data; false if it can't be written, or + the close, where a late write error shows, fails. *) proc write*(path, data: []U8): BOOL; var fd, n, at: INT; begin @@ -51,8 +52,7 @@ elsif n # Sys.errIntr then Sys.close(fd); return false; (* a signal broke in: write again *) end; end; - Sys.close(fd); - return true; + return Sys.closeChecked(fd) = 0; (* a write error may come only at the close *) end; (* The module's test. *)