From d878d16779f41dd84741bc40c642f271349cd034 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 29 Sep 2023 13:11:07 -0700 Subject: [PATCH] os: unset lang completely setlocale fails --- src/os/locale.zig | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/os/locale.zig b/src/os/locale.zig index 8a8e3293d..09d92b029 100644 --- a/src/os/locale.zig +++ b/src/os/locale.zig @@ -35,17 +35,10 @@ pub fn ensureLocale() void { // default. if (std.os.getenv("LANG")) |old_lang| { if (old_lang.len > 0) { - // The old_lang pointer can be invalidated by unsetenv so we need - // to make a copy. LANG should never be longer than 128 bytes. If - // it is, we just set it to "". - var buf: [128]u8 = undefined; - var fba = std.heap.FixedBufferAllocator.init(&buf); - const alloc = fba.allocator(); - const old_copy = alloc.dupeZ(u8, old_lang) catch ""; - - // Unset the lang and defer to reset the copy. + // We don't need to do both of these things but we do them + // both to be sure that lang is either empty or unset completely. + _ = setenv("LANG", "", 1); _ = unsetenv("LANG"); - defer _ = setenv("LANG", old_copy.ptr, 1); if (setlocale(LC_ALL, "")) |v| { log.info("setlocale after unset lang result={s}", .{v});