aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/os/TempDir.zig
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-05-07 18:29:21 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-07 18:29:21 +0300
commitdcfe11a7588fcd42471159453810abc9b7720a57 (patch)
treec32a77266028e73ca2382b96c96f8438a5fcd621 /vendor/libghostty-vt/src/os/TempDir.zig
parent2dfed860103c4e4505ac7f25def9fe37da1e1e6a (diff)
build: update libghostty-vt vendor
vendor ghostty 063ac3e and remove the musl libc++ link workaround. expose the new selection formatter and hyperlink uri apis for follow-up rendering work. add manual artifact validation for static linux builds.
Diffstat (limited to 'vendor/libghostty-vt/src/os/TempDir.zig')
-rw-r--r--vendor/libghostty-vt/src/os/TempDir.zig33
1 files changed, 11 insertions, 22 deletions
diff --git a/vendor/libghostty-vt/src/os/TempDir.zig b/vendor/libghostty-vt/src/os/TempDir.zig
index 2ddf18da..c3d344d9 100644
--- a/vendor/libghostty-vt/src/os/TempDir.zig
+++ b/vendor/libghostty-vt/src/os/TempDir.zig
@@ -3,10 +3,8 @@
const TempDir = @This();
const std = @import("std");
-const testing = std.testing;
const Dir = std.fs.Dir;
-const allocTmpDir = @import("file.zig").allocTmpDir;
-const freeTmpDir = @import("file.zig").freeTmpDir;
+const file = @import("file.zig");
const log = std.log.scoped(.tempdir);
@@ -18,28 +16,26 @@ parent: Dir,
/// Name buffer that name points into. Generally do not use. To get the
/// name call the name() function.
-name_buf: [TMP_PATH_LEN:0]u8,
+name_buf: [file.random_basename_len:0]u8,
/// Create the temporary directory.
pub fn init() !TempDir {
// Note: the tmp_path_buf sentinel is important because it ensures
- // we actually always have TMP_PATH_LEN+1 bytes of available space. We
- // need that so we can set the sentinel in the case we use all the
- // possible length.
- var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined;
- var rand_buf: [RANDOM_BYTES]u8 = undefined;
+ // we actually always have random_basename_len+1 bytes of available
+ // space. We need that so we can set the sentinel in the case we use
+ // all the possible length.
+ var tmp_path_buf: [file.random_basename_len:0]u8 = undefined;
const dir = dir: {
const cwd = std.fs.cwd();
- const tmp_dir = allocTmpDir(std.heap.page_allocator) orelse break :dir cwd;
- defer freeTmpDir(std.heap.page_allocator, tmp_dir);
+ const tmp_dir = try file.allocTmpDir(std.heap.page_allocator);
+ defer file.freeTmpDir(std.heap.page_allocator, tmp_dir);
break :dir try cwd.openDir(tmp_dir, .{});
};
// We now loop forever until we can find a directory that we can create.
while (true) {
- std.crypto.random.bytes(rand_buf[0..]);
- const tmp_path = b64_encoder.encode(&tmp_path_buf, &rand_buf);
+ const tmp_path = try file.randomBasename(&tmp_path_buf);
tmp_path_buf[tmp_path.len] = 0;
dir.makeDir(tmp_path) catch |err| switch (err) {
@@ -69,16 +65,9 @@ pub fn deinit(self: *TempDir) void {
log.err("error deleting temp dir err={}", .{err});
}
-// The amount of random bytes to get to determine our filename.
-const RANDOM_BYTES = 16;
-const TMP_PATH_LEN = b64_encoder.calcSize(RANDOM_BYTES);
-
-// Base64 encoder, replacing the standard `+/` with `-_` so that it can
-// be used in a file name on any filesystem.
-const b64_encoder = std.base64.Base64Encoder.init(b64_alphabet, null);
-const b64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*;
-
test {
+ const testing = std.testing;
+
var td = try init();
errdefer td.deinit();