diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index a76dfd3528..02d8693e2c 100644 --- a/lib/std/child_process.zig +++ b/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. diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index 540f7d395e..c7265a8923 100644 --- a/lib/std/fs/file.zig +++ b/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, .{}); } diff --git a/lib/std/fs/get_app_data_dir.zig b/lib/std/fs/get_app_data_dir.zig index bbc9c4b7bb..cb26e335de 100644 --- a/lib/std/fs/get_app_data_dir.zig +++ b/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; diff --git a/lib/std/os.zig b/lib/std/os.zig index 676d249e87..c39891c6b0 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2632,9 +2632,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. diff --git a/lib/std/os/uefi/protocols/simple_text_output_protocol.zig b/lib/std/os/uefi/protocols/simple_text_output_protocol.zig index 78358214a2..2a643ec834 100644 --- a/lib/std/os/uefi/protocols/simple_text_output_protocol.zig +++ b/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); } diff --git a/lib/std/os/uefi/tables/runtime_services.zig b/lib/std/os/uefi/tables/runtime_services.zig index 39d1aa2e3e..9e6861377b 100644 --- a/lib/std/os/uefi/tables/runtime_services.zig +++ b/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 diff --git a/lib/std/os/uefi/tables/system_table.zig b/lib/std/os/uefi/tables/system_table.zig index 6d949ee19c..40fec34d44 100644 --- a/lib/std/os/uefi/tables/system_table.zig +++ b/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, diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index b7b1edeb89..a6aeaa439a 100644 --- a/lib/std/os/windows.zig +++ b/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, diff --git a/lib/std/os/windows/bits.zig b/lib/std/os/windows/bits.zig index 7d87ae075a..328732e0c7 100644 --- a/lib/std/os/windows/bits.zig +++ b/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; diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index 1af68f4abd..9ec40240b6 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -7,7 +7,7 @@ pub extern "kernel32" fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) c pub extern "kernel32" fn CloseHandle(hObject: HANDLE) callconv(.Stdcall) BOOL; -pub extern "kernel32" fn CreateDirectoryW(lpPathName: [*]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) callconv(.Stdcall) BOOL; +pub extern "kernel32" fn CreateDirectoryW(lpPathName: [*:0]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) callconv(.Stdcall) BOOL; pub extern "kernel32" fn CreateEventExW( lpEventAttributes: ?*SECURITY_ATTRIBUTES, @@ -17,7 +17,7 @@ pub extern "kernel32" fn CreateEventExW( ) callconv(.Stdcall) ?HANDLE; pub extern "kernel32" 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" fn CreateProcessW( lpProcessInformation: *PROCESS_INFORMATION, ) callconv(.Stdcall) BOOL; -pub extern "kernel32" fn CreateSymbolicLinkW(lpSymlinkFileName: [*]const u16, lpTargetFileName: [*]const u16, dwFlags: DWORD) callconv(.Stdcall) BOOLEAN; +pub extern "kernel32" fn CreateSymbolicLinkW(lpSymlinkFileName: [*:0]const u16, lpTargetFileName: [*:0]const u16, dwFlags: DWORD) callconv(.Stdcall) BOOLEAN; pub extern "kernel32" fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) callconv(.Stdcall) ?HANDLE; @@ -63,19 +63,19 @@ pub extern "kernel32" fn DeviceIoControl( lpOverlapped: ?*OVERLAPPED, ) callconv(.Stdcall) BOOL; -pub extern "kernel32" fn DeleteFileW(lpFileName: [*]const u16) callconv(.Stdcall) BOOL; +pub extern "kernel32" fn DeleteFileW(lpFileName: [*:0]const u16) callconv(.Stdcall) BOOL; pub extern "kernel32" fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) callconv(.Stdcall) BOOL; pub extern "kernel32" fn ExitProcess(exit_code: UINT) callconv(.Stdcall) noreturn; -pub extern "kernel32" fn FindFirstFileW(lpFileName: [*]const u16, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) HANDLE; +pub extern "kernel32" fn FindFirstFileW(lpFileName: [*:0]const u16, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) HANDLE; pub extern "kernel32" fn FindClose(hFindFile: HANDLE) callconv(.Stdcall) BOOL; pub extern "kernel32" fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) BOOL; -pub extern "kernel32" fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) callconv(.Stdcall) DWORD; +pub extern "kernel32" fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: [*]u16, nSize: DWORD, Arguments: ?*va_list) callconv(.Stdcall) DWORD; -pub extern "kernel32" fn FreeEnvironmentStringsW(penv: [*]u16) callconv(.Stdcall) BOOL; +pub extern "kernel32" fn FreeEnvironmentStringsW(penv: [*:0]u16) callconv(.Stdcall) BOOL; pub extern "kernel32" fn GetCommandLineA() callconv(.Stdcall) LPSTR; @@ -88,9 +88,9 @@ pub extern "kernel32" fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: ?[ pub extern "kernel32" fn GetCurrentThread() callconv(.Stdcall) HANDLE; pub extern "kernel32" fn GetCurrentThreadId() callconv(.Stdcall) DWORD; -pub extern "kernel32" fn GetEnvironmentStringsW() callconv(.Stdcall) ?[*]u16; +pub extern "kernel32" fn GetEnvironmentStringsW() callconv(.Stdcall) ?[*:0]u16; -pub extern "kernel32" fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) callconv(.Stdcall) DWORD; +pub extern "kernel32" fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) callconv(.Stdcall) DWORD; pub extern "kernel32" fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) callconv(.Stdcall) BOOL; @@ -150,8 +150,8 @@ pub extern "kernel32" fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE_T, flAllo pub extern "kernel32" fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) callconv(.Stdcall) BOOL; pub extern "kernel32" fn MoveFileExW( - lpExistingFileName: [*]const u16, - lpNewFileName: [*]const u16, + lpExistingFileName: [*:0]const u16, + lpNewFileName: [*:0]const u16, dwFlags: DWORD, ) callconv(.Stdcall) BOOL; @@ -180,7 +180,7 @@ pub extern "kernel32" fn ReadFile( in_out_lpOverlapped: ?*OVERLAPPED, ) callconv(.Stdcall) BOOL; -pub extern "kernel32" fn RemoveDirectoryW(lpPathName: [*]const u16) callconv(.Stdcall) BOOL; +pub extern "kernel32" fn RemoveDirectoryW(lpPathName: [*:0]const u16) callconv(.Stdcall) BOOL; pub extern "kernel32" fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) callconv(.Stdcall) BOOL; @@ -234,7 +234,7 @@ pub extern "kernel32" fn WriteFile( pub extern "kernel32" fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) callconv(.Stdcall) BOOL; -pub extern "kernel32" fn LoadLibraryW(lpLibFileName: [*]const u16) callconv(.Stdcall) ?HMODULE; +pub extern "kernel32" fn LoadLibraryW(lpLibFileName: [*:0]const u16) callconv(.Stdcall) ?HMODULE; pub extern "kernel32" fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) callconv(.Stdcall) ?FARPROC; diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig index 695cd77274..08f22386f9 100644 --- a/lib/std/os/windows/ntdll.zig +++ b/lib/std/os/windows/ntdll.zig @@ -35,9 +35,9 @@ pub extern "NtDll" fn NtDeviceIoControlFile( ) callconv(.Stdcall) NTSTATUS; pub extern "NtDll" fn NtClose(Handle: HANDLE) callconv(.Stdcall) NTSTATUS; pub extern "NtDll" fn RtlDosPathNameToNtPathName_U( - DosPathName: [*]const u16, + DosPathName: [*:0]const u16, NtPathName: *UNICODE_STRING, - NtFileNamePart: ?*?[*]const u16, + NtFileNamePart: ?*?[*:0]const u16, DirectoryInfo: ?*CURDIR, ) callconv(.Stdcall) BOOL; pub extern "NtDll" fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) callconv(.Stdcall) void; diff --git a/lib/std/os/windows/shell32.zig b/lib/std/os/windows/shell32.zig index aa1667d01d..762589c6de 100644 --- a/lib/std/os/windows/shell32.zig +++ b/lib/std/os/windows/shell32.zig @@ -1,3 +1,3 @@ usingnamespace @import("bits.zig"); -pub extern "shell32" fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) callconv(.Stdcall) HRESULT; +pub extern "shell32" fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*:0]WCHAR) callconv(.Stdcall) HRESULT; diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 4dfe1c87d3..3d16748447 100644 --- a/lib/std/unicode.zig +++ b/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.