Commit 2662e50d27
Changed files (13)
lib/std/fs/file.zig
@@ -60,7 +60,7 @@ pub const File = struct {
}
/// Deprecated; call `std.fs.Dir.openFileW` directly.
- pub fn openReadW(path_w: [*]const u16) OpenError!File {
+ pub fn openReadW(path_w: [*:0]const u16) OpenError!File {
return std.fs.cwd().openFileW(path_w, .{});
}
lib/std/fs/get_app_data_dir.zig
@@ -15,7 +15,7 @@ pub const GetAppDataDirError = error{
pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataDirError![]u8 {
switch (builtin.os) {
.windows => {
- var dir_path_ptr: [*]u16 = undefined;
+ var dir_path_ptr: [*:0]u16 = undefined;
switch (os.windows.shell32.SHGetKnownFolderPath(
&os.windows.FOLDERID_LocalAppData,
os.windows.KF_FLAG_CREATE,
@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
)) {
os.windows.S_OK => {
defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr));
- const global_dir = unicode.utf16leToUtf8Alloc(allocator, utf16lePtrSlice(dir_path_ptr)) catch |err| switch (err) {
+ const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.toSliceConst(u16, dir_path_ptr)) catch |err| switch (err) {
error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,
@@ -55,12 +55,6 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
}
}
-fn utf16lePtrSlice(ptr: [*]const u16) []const u16 {
- var index: usize = 0;
- while (ptr[index] != 0) : (index += 1) {}
- return ptr[0..index];
-}
-
test "getAppDataDir" {
var buf: [512]u8 = undefined;
const allocator = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator;
lib/std/os/uefi/protocols/simple_text_output_protocol.zig
@@ -4,8 +4,8 @@ const Guid = uefi.Guid;
/// Character output devices
pub const SimpleTextOutputProtocol = extern struct {
_reset: extern fn (*const SimpleTextOutputProtocol, bool) usize,
- _output_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize,
- _test_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize,
+ _output_string: extern fn (*const SimpleTextOutputProtocol, [*:0]const u16) usize,
+ _test_string: extern fn (*const SimpleTextOutputProtocol, [*:0]const u16) usize,
_query_mode: extern fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) usize,
_set_mode: extern fn (*const SimpleTextOutputProtocol, usize) usize,
_set_attribute: extern fn (*const SimpleTextOutputProtocol, usize) usize,
@@ -20,12 +20,12 @@ pub const SimpleTextOutputProtocol = extern struct {
}
/// Writes a string to the output device.
- pub fn outputString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize {
+ pub fn outputString(self: *const SimpleTextOutputProtocol, msg: [*:0]const u16) usize {
return self._output_string(self, msg);
}
/// Verifies that all characters in a string can be output to the target device.
- pub fn testString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize {
+ pub fn testString(self: *const SimpleTextOutputProtocol, msg: [*:0]const u16) usize {
return self._test_string(self, msg);
}
lib/std/os/uefi/tables/runtime_services.zig
@@ -25,13 +25,13 @@ pub const RuntimeServices = extern struct {
convertPointer: usize, // TODO
/// Returns the value of a variable.
- getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
+ getVariable: extern fn ([*:0]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
/// Enumerates the current variable names.
getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,
/// Sets the value of a variable.
- setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
+ setVariable: extern fn ([*:0]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
getNextHighMonotonicCount: usize, // TODO
lib/std/os/uefi/tables/system_table.zig
@@ -19,7 +19,7 @@ pub const SystemTable = extern struct {
hdr: TableHeader,
/// A null-terminated string that identifies the vendor that produces the system firmware of the platform.
- firmware_vendor: [*]u16,
+ firmware_vendor: [*:0]u16,
firmware_revision: u32,
console_in_handle: ?Handle,
con_in: ?*SimpleTextInputProtocol,
lib/std/os/windows/bits.zig
@@ -33,17 +33,17 @@ pub const FARPROC = *@OpaqueType();
pub const INT = c_int;
pub const LPBYTE = *BYTE;
pub const LPCH = *CHAR;
-pub const LPCSTR = [*]const CHAR;
-pub const LPCTSTR = [*]const TCHAR;
+pub const LPCSTR = [*:0]const CHAR;
+pub const LPCTSTR = [*:0]const TCHAR;
pub const LPCVOID = *const c_void;
pub const LPDWORD = *DWORD;
-pub const LPSTR = [*]CHAR;
+pub const LPSTR = [*:0]CHAR;
pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
pub const LPVOID = *c_void;
-pub const LPWSTR = [*]WCHAR;
-pub const LPCWSTR = [*]const WCHAR;
+pub const LPWSTR = [*:0]WCHAR;
+pub const LPCWSTR = [*:0]const WCHAR;
pub const PVOID = *c_void;
-pub const PWSTR = [*]WCHAR;
+pub const PWSTR = [*:0]WCHAR;
pub const SIZE_T = usize;
pub const TCHAR = if (UNICODE) WCHAR else u8;
pub const UINT = c_uint;
lib/std/os/windows/kernel32.zig
@@ -7,7 +7,7 @@ pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVE
pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;
-pub extern "kernel32" stdcallcc fn CreateDirectoryW(lpPathName: [*]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) BOOL;
+pub extern "kernel32" stdcallcc fn CreateDirectoryW(lpPathName: [*:0]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) BOOL;
pub extern "kernel32" stdcallcc fn CreateEventExW(
lpEventAttributes: ?*SECURITY_ATTRIBUTES,
@@ -17,7 +17,7 @@ pub extern "kernel32" stdcallcc fn CreateEventExW(
) ?HANDLE;
pub extern "kernel32" stdcallcc fn CreateFileW(
- lpFileName: [*]const u16, // TODO null terminated pointer type
+ lpFileName: [*:0]const u16,
dwDesiredAccess: DWORD,
dwShareMode: DWORD,
lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,
@@ -46,7 +46,7 @@ pub extern "kernel32" stdcallcc fn CreateProcessW(
lpProcessInformation: *PROCESS_INFORMATION,
) BOOL;
-pub extern "kernel32" stdcallcc fn CreateSymbolicLinkW(lpSymlinkFileName: [*]const u16, lpTargetFileName: [*]const u16, dwFlags: DWORD) BOOLEAN;
+pub extern "kernel32" stdcallcc fn CreateSymbolicLinkW(lpSymlinkFileName: [*:0]const u16, lpTargetFileName: [*:0]const u16, dwFlags: DWORD) BOOLEAN;
pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) ?HANDLE;
@@ -63,19 +63,19 @@ pub extern "kernel32" stdcallcc fn DeviceIoControl(
lpOverlapped: ?*OVERLAPPED,
) BOOL;
-pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL;
+pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*:0]const u16) BOOL;
pub extern "kernel32" stdcallcc fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) BOOL;
pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn;
-pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*]const u16, lpFindFileData: *WIN32_FIND_DATAW) HANDLE;
+pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*:0]const u16, lpFindFileData: *WIN32_FIND_DATAW) HANDLE;
pub extern "kernel32" stdcallcc fn FindClose(hFindFile: HANDLE) BOOL;
pub extern "kernel32" stdcallcc fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) BOOL;
-pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) DWORD;
+pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: [*]u16, nSize: DWORD, Arguments: ?*va_list) DWORD;
-pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*]u16) BOOL;
+pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*:0]u16) BOOL;
pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;
@@ -88,9 +88,9 @@ pub extern "kernel32" stdcallcc fn GetCurrentDirectoryW(nBufferLength: DWORD, lp
pub extern "kernel32" stdcallcc fn GetCurrentThread() HANDLE;
pub extern "kernel32" stdcallcc fn GetCurrentThreadId() DWORD;
-pub extern "kernel32" stdcallcc fn GetEnvironmentStringsW() ?[*]u16;
+pub extern "kernel32" stdcallcc fn GetEnvironmentStringsW() ?[*:0]u16;
-pub extern "kernel32" stdcallcc fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) DWORD;
+pub extern "kernel32" stdcallcc fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) DWORD;
pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) BOOL;
@@ -150,8 +150,8 @@ pub extern "kernel32" stdcallcc fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE
pub extern "kernel32" stdcallcc fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) BOOL;
pub extern "kernel32" stdcallcc fn MoveFileExW(
- lpExistingFileName: [*]const u16,
- lpNewFileName: [*]const u16,
+ lpExistingFileName: [*:0]const u16,
+ lpNewFileName: [*:0]const u16,
dwFlags: DWORD,
) BOOL;
@@ -180,7 +180,7 @@ pub extern "kernel32" stdcallcc fn ReadFile(
in_out_lpOverlapped: ?*OVERLAPPED,
) BOOL;
-pub extern "kernel32" stdcallcc fn RemoveDirectoryW(lpPathName: [*]const u16) BOOL;
+pub extern "kernel32" stdcallcc fn RemoveDirectoryW(lpPathName: [*:0]const u16) BOOL;
pub extern "kernel32" stdcallcc fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) BOOL;
@@ -234,7 +234,7 @@ pub extern "kernel32" stdcallcc fn WriteFile(
pub extern "kernel32" stdcallcc fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) BOOL;
-pub extern "kernel32" stdcallcc fn LoadLibraryW(lpLibFileName: [*]const u16) ?HMODULE;
+pub extern "kernel32" stdcallcc fn LoadLibraryW(lpLibFileName: [*:0]const u16) ?HMODULE;
pub extern "kernel32" stdcallcc fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) ?FARPROC;
lib/std/os/windows/ntdll.zig
@@ -35,9 +35,9 @@ pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile(
) NTSTATUS;
pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS;
pub extern "NtDll" stdcallcc fn RtlDosPathNameToNtPathName_U(
- DosPathName: [*]const u16,
+ DosPathName: [*:0]const u16,
NtPathName: *UNICODE_STRING,
- NtFileNamePart: ?*?[*]const u16,
+ NtFileNamePart: ?*?[*:0]const u16,
DirectoryInfo: ?*CURDIR,
) BOOL;
pub extern "NtDll" stdcallcc fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) void;
lib/std/os/windows/shell32.zig
@@ -1,3 +1,3 @@
usingnamespace @import("bits.zig");
-pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT;
+pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*:0]WCHAR) HRESULT;
lib/std/os/windows.zig
@@ -60,7 +60,7 @@ pub fn CreateFile(
}
pub fn CreateFileW(
- file_path_w: [*]const u16,
+ file_path_w: [*:0]const u16,
desired_access: DWORD,
share_mode: DWORD,
lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,
@@ -425,8 +425,8 @@ pub fn CreateSymbolicLink(
}
pub fn CreateSymbolicLinkW(
- sym_link_path: [*]const u16,
- target_path: [*]const u16,
+ sym_link_path: [*:0]const u16,
+ target_path: [*:0]const u16,
flags: DWORD,
) CreateSymbolicLinkError!void {
if (kernel32.CreateSymbolicLinkW(sym_link_path, target_path, flags) == 0) {
@@ -449,7 +449,7 @@ pub fn DeleteFile(filename: []const u8) DeleteFileError!void {
return DeleteFileW(&filename_w);
}
-pub fn DeleteFileW(filename: [*]const u16) DeleteFileError!void {
+pub fn DeleteFileW(filename: [*:0]const u16) DeleteFileError!void {
if (kernel32.DeleteFileW(filename) == 0) {
switch (kernel32.GetLastError()) {
ERROR.FILE_NOT_FOUND => return error.FileNotFound,
@@ -471,7 +471,7 @@ pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) Move
return MoveFileExW(&old_path_w, &new_path_w, flags);
}
-pub fn MoveFileExW(old_path: [*]const u16, new_path: [*]const u16, flags: DWORD) MoveFileError!void {
+pub fn MoveFileExW(old_path: [*:0]const u16, new_path: [*:0]const u16, flags: DWORD) MoveFileError!void {
if (kernel32.MoveFileExW(old_path, new_path, flags) == 0) {
switch (kernel32.GetLastError()) {
else => |err| return unexpectedError(err),
@@ -490,7 +490,7 @@ pub fn CreateDirectory(pathname: []const u8, attrs: ?*SECURITY_ATTRIBUTES) Creat
return CreateDirectoryW(&pathname_w, attrs);
}
-pub fn CreateDirectoryW(pathname: [*]const u16, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void {
+pub fn CreateDirectoryW(pathname: [*:0]const u16, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void {
if (kernel32.CreateDirectoryW(pathname, attrs) == 0) {
switch (kernel32.GetLastError()) {
ERROR.ALREADY_EXISTS => return error.PathAlreadyExists,
@@ -511,7 +511,7 @@ pub fn RemoveDirectory(dir_path: []const u8) RemoveDirectoryError!void {
return RemoveDirectoryW(&dir_path_w);
}
-pub fn RemoveDirectoryW(dir_path_w: [*]const u16) RemoveDirectoryError!void {
+pub fn RemoveDirectoryW(dir_path_w: [*:0]const u16) RemoveDirectoryError!void {
if (kernel32.RemoveDirectoryW(dir_path_w) == 0) {
switch (kernel32.GetLastError()) {
ERROR.PATH_NOT_FOUND => return error.FileNotFound,
@@ -602,7 +602,7 @@ pub fn GetFinalPathNameByHandleW(
buf_ptr: [*]u16,
buf_len: DWORD,
flags: DWORD,
-) GetFinalPathNameByHandleError!DWORD {
+) GetFinalPathNameByHandleError![:0]u16 {
const rc = kernel32.GetFinalPathNameByHandleW(hFile, buf_ptr, buf_len, flags);
if (rc == 0) {
switch (kernel32.GetLastError()) {
@@ -614,7 +614,7 @@ pub fn GetFinalPathNameByHandleW(
else => |err| return unexpectedError(err),
}
}
- return rc;
+ return buf_ptr[0..rc :0];
}
pub const GetFileSizeError = error{Unexpected};
@@ -640,7 +640,7 @@ pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD {
return GetFileAttributesW(&filename_w);
}
-pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD {
+pub fn GetFileAttributesW(lpFileName: [*:0]const u16) GetFileAttributesError!DWORD {
const rc = kernel32.GetFileAttributesW(lpFileName);
if (rc == INVALID_FILE_ATTRIBUTES) {
switch (kernel32.GetLastError()) {
@@ -733,14 +733,14 @@ pub fn WSAIoctl(
const GetModuleFileNameError = error{Unexpected};
-pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 {
+pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![:0]u16 {
const rc = kernel32.GetModuleFileNameW(hModule, buf_ptr, buf_len);
if (rc == 0) {
switch (kernel32.GetLastError()) {
else => |err| return unexpectedError(err),
}
}
- return buf_ptr[0..rc];
+ return buf_ptr[0..rc :0];
}
pub const TerminateProcessError = error{Unexpected};
@@ -779,11 +779,11 @@ pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetCon
pub const GetEnvironmentStringsError = error{OutOfMemory};
-pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*]u16 {
+pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*:0]u16 {
return kernel32.GetEnvironmentStringsW() orelse return error.OutOfMemory;
}
-pub fn FreeEnvironmentStringsW(penv: [*]u16) void {
+pub fn FreeEnvironmentStringsW(penv: [*:0]u16) void {
assert(kernel32.FreeEnvironmentStringsW(penv) != 0);
}
@@ -792,7 +792,7 @@ pub const GetEnvironmentVariableError = error{
Unexpected,
};
-pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) GetEnvironmentVariableError!DWORD {
+pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) GetEnvironmentVariableError!DWORD {
const rc = kernel32.GetEnvironmentVariableW(lpName, lpBuffer, nSize);
if (rc == 0) {
switch (kernel32.GetLastError()) {
@@ -850,7 +850,7 @@ pub const LoadLibraryError = error{
Unexpected,
};
-pub fn LoadLibraryW(lpLibFileName: [*]const u16) LoadLibraryError!HMODULE {
+pub fn LoadLibraryW(lpLibFileName: [*:0]const u16) LoadLibraryError!HMODULE {
return kernel32.LoadLibraryW(lpLibFileName) orelse {
switch (kernel32.GetLastError()) {
ERROR.FILE_NOT_FOUND => return error.FileNotFound,
lib/std/child_process.zig
@@ -582,9 +582,7 @@ pub const ChildProcess = struct {
};
var piProcInfo: windows.PROCESS_INFORMATION = undefined;
- const cwd_slice = if (self.cwd) |cwd| try cstr.addNullByte(self.allocator, cwd) else null;
- defer if (cwd_slice) |cwd| self.allocator.free(cwd);
- const cwd_w = if (cwd_slice) |cwd| try unicode.utf8ToUtf16LeWithNull(self.allocator, cwd) else null;
+ const cwd_w = if (self.cwd) |cwd| try unicode.utf8ToUtf16LeWithNull(self.allocator, cwd) else null;
defer if (cwd_w) |cwd| self.allocator.free(cwd);
const cwd_w_ptr = if (cwd_w) |cwd| cwd.ptr else null;
@@ -701,7 +699,7 @@ pub const ChildProcess = struct {
}
};
-fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, cwd_ptr: ?[*]u16, lpStartupInfo: *windows.STARTUPINFOW, lpProcessInformation: *windows.PROCESS_INFORMATION) !void {
+fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u16, cwd_ptr: ?[*:0]u16, lpStartupInfo: *windows.STARTUPINFOW, lpProcessInformation: *windows.PROCESS_INFORMATION) !void {
// TODO the docs for environment pointer say:
// > A pointer to the environment block for the new process. If this parameter
// > is NULL, the new process uses the environment of the calling process.
lib/std/os.zig
@@ -2634,9 +2634,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real
defer windows.CloseHandle(h_file);
var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;
- const wide_len = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS);
- assert(wide_len <= wide_buf.len);
- const wide_slice = wide_buf[0..wide_len];
+ const wide_slice = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS);
// Windows returns \\?\ prepended to the path.
// We strip it to make this function consistent across platforms.
lib/std/unicode.zig
@@ -544,8 +544,7 @@ test "utf16leToUtf8" {
}
}
-/// TODO type for null terminated pointer
-pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![]u16 {
+pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![:0]u16 {
var result = std.ArrayList(u16).init(allocator);
// optimistically guess that it will not require surrogate pairs
try result.ensureCapacity(utf8.len + 1);
@@ -567,7 +566,7 @@ pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![]u16
}
try result.append(0);
- return result.toOwnedSlice();
+ return result.toOwnedSlice()[0..:0];
}
/// Returns index of next character. If exact fit, returned index equals output slice length.