diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/host_io.zig | 19 | ||||
| -rw-r--r-- | src/tape.zig | 7 | ||||
| -rw-r--r-- | src/upgrade.zig | 14 |
3 files changed, 8 insertions, 32 deletions
diff --git a/src/host_io.zig b/src/host_io.zig index 2f1d8a3d..51699986 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -1441,21 +1441,10 @@ pub const Shell = struct { const path = std.fmt.bufPrintSentinel(path_buf, "{s}", .{template}, 0) catch return 0; const fd = mkstemp(path.ptr); if (fd < 0) return 0; - var off: usize = 0; - while (off < contents.len) { - const n = libc.write(fd, contents[off..].ptr, contents.len - off); - if (n < 0) { - if (libc.errno(n) == .INTR) continue; - _ = libc.close(fd); - _ = libc.unlink(path.ptr); - return 0; - } - if (n == 0) { - _ = libc.close(fd); - _ = libc.unlink(path.ptr); - return 0; - } - off += @intCast(n); + if (!writeFd(fd, contents)) { + _ = libc.close(fd); + _ = libc.unlink(path.ptr); + return 0; } if (libc.close(fd) != 0) { _ = libc.unlink(path.ptr); diff --git a/src/tape.zig b/src/tape.zig index 29b1197d..56789f44 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -283,12 +283,7 @@ pub const Tape = struct { // A tape in memory (a replica's, an authority's stream) is taken // by whoever holds it. if (t.fd < 0) return; - var at: usize = 0; - while (at < t.buf.items.len) { - const n = libc.write(t.fd, t.buf.items[at..].ptr, t.buf.items.len - at); - if (n <= 0) break; - at += @intCast(n); - } + _ = host_io.writeFd(t.fd, t.buf.items); t.buf.clearRetainingCapacity(); } diff --git a/src/upgrade.zig b/src/upgrade.zig index 2e5f683f..d8f8f3c3 100644 --- a/src/upgrade.zig +++ b/src/upgrade.zig @@ -339,17 +339,9 @@ fn writeDump(path: [:0]const u8, bytes: []const u8) bool { const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true, .CLOEXEC = true }, @as(libc.mode_t, 0o600)); if (fd < 0) return false; defer _ = libc.close(fd); - var at: usize = 0; - while (at < bytes.len) { - const n = libc.write(fd, bytes[at..].ptr, bytes.len - at); - if (n < 0 and libc.errno(n) == .INTR) continue; - if (n <= 0) { - _ = libc.unlink(path); - return false; - } - at += @intCast(n); - } - return true; + if (@import("host_io.zig").writeFd(fd, bytes)) return true; + _ = libc.unlink(path); + return false; } /// An Upgrade's dump, the terminal's and the window's alike: written |
