Skip to content

Commit 67b5783

Browse files
authored
os: RANDOM_BASENAME_LEN -> random_basename_len (ghostty-org#12467)
2 parents e9ca0f8 + 13ada38 commit 67b5783

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/os/TempDir.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ parent: Dir,
1616

1717
/// Name buffer that name points into. Generally do not use. To get the
1818
/// name call the name() function.
19-
name_buf: [file.RANDOM_BASENAME_LEN:0]u8,
19+
name_buf: [file.random_basename_len:0]u8,
2020

2121
/// Create the temporary directory.
2222
pub fn init() !TempDir {
2323
// Note: the tmp_path_buf sentinel is important because it ensures
24-
// we actually always have RANDOM_BASENAME_LEN+1 bytes of available
24+
// we actually always have random_basename_len+1 bytes of available
2525
// space. We need that so we can set the sentinel in the case we use
2626
// all the possible length.
27-
var tmp_path_buf: [file.RANDOM_BASENAME_LEN:0]u8 = undefined;
27+
var tmp_path_buf: [file.random_basename_len:0]u8 = undefined;
2828

2929
const dir = dir: {
3030
const cwd = std.fs.cwd();

src/os/file.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ const b64_encoder = std.base64.url_safe_no_pad.Encoder;
8686
pub const RandomBasenameError = error{BufferTooSmall};
8787

8888
/// Length of the basename produced by `randomBasename`.
89-
pub const RANDOM_BASENAME_LEN = b64_encoder.calcSize(random_basename_bytes);
89+
pub const random_basename_len = b64_encoder.calcSize(random_basename_bytes);
9090

9191
/// Write a random filesystem-safe base64 basename of length
92-
/// `RANDOM_BASENAME_LEN` into `buf` and return a slice over the
92+
/// `random_basename_len` into `buf` and return a slice over the
9393
/// written bytes. Returns `error.BufferTooSmall` if `buf` is too
9494
/// short.
9595
pub fn randomBasename(buf: []u8) RandomBasenameError![]const u8 {
96-
if (buf.len < RANDOM_BASENAME_LEN) return error.BufferTooSmall;
96+
if (buf.len < random_basename_len) return error.BufferTooSmall;
9797
var rand_buf: [random_basename_bytes]u8 = undefined;
9898
std.crypto.random.bytes(&rand_buf);
99-
return b64_encoder.encode(buf[0..RANDOM_BASENAME_LEN], &rand_buf);
99+
return b64_encoder.encode(buf[0..random_basename_len], &rand_buf);
100100
}
101101

102102
/// Return a freshly-allocated path of the form `{TMPDIR}/{prefix}{random}`.
@@ -111,7 +111,7 @@ pub fn randomTmpPath(
111111
) std.mem.Allocator.Error![]u8 {
112112
const tmp_dir = allocTmpDir(allocator) orelse "/tmp";
113113
defer freeTmpDir(allocator, tmp_dir);
114-
var name_buf: [RANDOM_BASENAME_LEN]u8 = undefined;
114+
var name_buf: [random_basename_len]u8 = undefined;
115115
const basename = randomBasename(&name_buf) catch unreachable;
116116
return std.fmt.allocPrint(
117117
allocator,
@@ -123,14 +123,14 @@ pub fn randomTmpPath(
123123
test randomBasename {
124124
const testing = std.testing;
125125

126-
var buf: [RANDOM_BASENAME_LEN]u8 = undefined;
126+
var buf: [random_basename_len]u8 = undefined;
127127
const name = try randomBasename(&buf);
128-
try testing.expectEqual(RANDOM_BASENAME_LEN, name.len);
128+
try testing.expectEqual(random_basename_len, name.len);
129129
for (name) |c| {
130130
const ok = std.ascii.isAlphanumeric(c) or c == '-' or c == '_';
131131
try testing.expect(ok);
132132
}
133133

134-
var small: [RANDOM_BASENAME_LEN - 1]u8 = undefined;
134+
var small: [random_basename_len - 1]u8 = undefined;
135135
try testing.expectError(error.BufferTooSmall, randomBasename(&small));
136136
}

0 commit comments

Comments
 (0)