diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-02-25 01:00:25 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-25 01:00:25 -0800 |
| commit | 6c2eb0f131588be111652a755a4492ff72d16440 (patch) | |
| tree | 0d317950da0694df32c4eb088278662f159e8736 /lib/std/Thread.zig | |
| parent | 63ea3e172e2788856cfb69b2f6085930a1c69d5b (diff) | |
| parent | 9fec608b3bbe3c00528e01bd09aa29f9b9f97415 (diff) | |
| download | zig-6c2eb0f131588be111652a755a4492ff72d16440.tar.gz zig-6c2eb0f131588be111652a755a4492ff72d16440.zip | |
Merge pull request #19005 from squeek502/wtf
Fix handling of Windows (WTF-16) and WASI (UTF-8) paths, etc
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index c3f628da79..ae794f44af 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -91,7 +91,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { }, .windows => { var buf: [max_name_len]u16 = undefined; - const len = try std.unicode.utf8ToUtf16Le(&buf, name); + const len = try std.unicode.wtf8ToWtf16Le(&buf, name); const byte_len = math.cast(c_ushort, len * 2) orelse return error.NameTooLong; // Note: NT allocates its own copy, no use-after-free here. @@ -157,17 +157,12 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { } pub const GetNameError = error{ - // For Windows, the name is converted from UTF16 to UTF8 - CodepointTooLarge, - Utf8CannotEncodeSurrogateHalf, - DanglingSurrogateHalf, - ExpectedSecondSurrogateHalf, - UnexpectedSecondSurrogateHalf, - Unsupported, Unexpected, } || os.PrctlError || os.ReadError || std.fs.File.OpenError || std.fmt.BufPrintError; +/// On Windows, the result is encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). +/// On other platforms, the result is an opaque sequence of bytes with no particular encoding. pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]const u8 { buffer_ptr[max_name_len] = 0; var buffer: [:0]u8 = buffer_ptr; @@ -213,7 +208,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co )) { .SUCCESS => { const string = @as(*const os.windows.UNICODE_STRING, @ptrCast(&buf)); - const len = try std.unicode.utf16leToUtf8(buffer, string.Buffer[0 .. string.Length / 2]); + const len = std.unicode.wtf16LeToWtf8(buffer, string.Buffer[0 .. string.Length / 2]); return if (len > 0) buffer[0..len] else null; }, .NOT_IMPLEMENTED => return error.Unsupported, |
