authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-12-28 16:40:59+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-12-29 10:35:05+11:00
log2662e50d27006396a4b6c776dc757e883b836fcc
tree7a2fbe1e5b5efff105d4194d7c32ae0af8aa71d0
parentcb02125415b516b13824fe90aca19c6fc9203cda
signature Commit is signed but in an unrecognized format.

std: sentinel terminated pointers for utf16 apis


13 files changed, 53 insertions(+), 64 deletions(-)

lib/std/child_process.zig+2-4
......@@ -582,9 +582,7 @@ pub const ChildProcess = struct {
582582 };
583583 var piProcInfo: windows.PROCESS_INFORMATION = undefined;
584584
585 const cwd_slice = if (self.cwd) |cwd| try cstr.addNullByte(self.allocator, cwd) else null;
586 defer if (cwd_slice) |cwd| self.allocator.free(cwd);
587 const cwd_w = if (cwd_slice) |cwd| try unicode.utf8ToUtf16LeWithNull(self.allocator, cwd) else null;
585 const cwd_w = if (self.cwd) |cwd| try unicode.utf8ToUtf16LeWithNull(self.allocator, cwd) else null;
588586 defer if (cwd_w) |cwd| self.allocator.free(cwd);
589587 const cwd_w_ptr = if (cwd_w) |cwd| cwd.ptr else null;
590588
......@@ -701,7 +699,7 @@ pub const ChildProcess = struct {
701699 }
702700};
703701
704fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, cwd_ptr: ?[*]u16, lpStartupInfo: *windows.STARTUPINFOW, lpProcessInformation: *windows.PROCESS_INFORMATION) !void {
702fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u16, cwd_ptr: ?[*:0]u16, lpStartupInfo: *windows.STARTUPINFOW, lpProcessInformation: *windows.PROCESS_INFORMATION) !void {
705703 // TODO the docs for environment pointer say:
706704 // > A pointer to the environment block for the new process. If this parameter
707705 // > is NULL, the new process uses the environment of the calling process.
lib/std/fs/file.zig+1-1
......@@ -60,7 +60,7 @@ pub const File = struct {
6060 }
6161
6262 /// Deprecated; call `std.fs.Dir.openFileW` directly.
63 pub fn openReadW(path_w: [*]const u16) OpenError!File {
63 pub fn openReadW(path_w: [*:0]const u16) OpenError!File {
6464 return std.fs.cwd().openFileW(path_w, .{});
6565 }
6666
lib/std/fs/get_app_data_dir.zig+2-8
......@@ -15,7 +15,7 @@ pub const GetAppDataDirError = error{
1515pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataDirError![]u8 {
1616 switch (builtin.os) {
1717 .windows => {
18 var dir_path_ptr: [*]u16 = undefined;
18 var dir_path_ptr: [*:0]u16 = undefined;
1919 switch (os.windows.shell32.SHGetKnownFolderPath(
2020 &os.windows.FOLDERID_LocalAppData,
2121 os.windows.KF_FLAG_CREATE,
......@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
2424 )) {
2525 os.windows.S_OK => {
2626 defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr));
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, utf16lePtrSlice(dir_path_ptr)) catch |err| switch (err) {
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.toSliceConst(u16, dir_path_ptr)) catch |err| switch (err) {
2828 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
2929 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
3030 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,
......@@ -55,12 +55,6 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
5555 }
5656}
5757
58fn utf16lePtrSlice(ptr: [*]const u16) []const u16 {
59 var index: usize = 0;
60 while (ptr[index] != 0) : (index += 1) {}
61 return ptr[0..index];
62}
63
6458test "getAppDataDir" {
6559 var buf: [512]u8 = undefined;
6660 const allocator = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator;
lib/std/os.zig+1-3
......@@ -2634,9 +2634,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real
26342634 defer windows.CloseHandle(h_file);
26352635
26362636 var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;
2637 const wide_len = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS);
2638 assert(wide_len <= wide_buf.len);
2639 const wide_slice = wide_buf[0..wide_len];
2637 const wide_slice = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS);
26402638
26412639 // Windows returns \\?\ prepended to the path.
26422640 // We strip it to make this function consistent across platforms.
lib/std/os/uefi/protocols/simple_text_output_protocol.zig+4-4
......@@ -4,8 +4,8 @@ const Guid = uefi.Guid;
44/// Character output devices
55pub const SimpleTextOutputProtocol = extern struct {
66 _reset: extern fn (*const SimpleTextOutputProtocol, bool) usize,
7 _output_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize,
8 _test_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize,
7 _output_string: extern fn (*const SimpleTextOutputProtocol, [*:0]const u16) usize,
8 _test_string: extern fn (*const SimpleTextOutputProtocol, [*:0]const u16) usize,
99 _query_mode: extern fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) usize,
1010 _set_mode: extern fn (*const SimpleTextOutputProtocol, usize) usize,
1111 _set_attribute: extern fn (*const SimpleTextOutputProtocol, usize) usize,
......@@ -20,12 +20,12 @@ pub const SimpleTextOutputProtocol = extern struct {
2020 }
2121
2222 /// Writes a string to the output device.
23 pub fn outputString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize {
23 pub fn outputString(self: *const SimpleTextOutputProtocol, msg: [*:0]const u16) usize {
2424 return self._output_string(self, msg);
2525 }
2626
2727 /// Verifies that all characters in a string can be output to the target device.
28 pub fn testString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize {
28 pub fn testString(self: *const SimpleTextOutputProtocol, msg: [*:0]const u16) usize {
2929 return self._test_string(self, msg);
3030 }
3131
lib/std/os/uefi/tables/runtime_services.zig+2-2
......@@ -25,13 +25,13 @@ pub const RuntimeServices = extern struct {
2525 convertPointer: usize, // TODO
2626
2727 /// Returns the value of a variable.
28 getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
28 getVariable: extern fn ([*:0]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
2929
3030 /// Enumerates the current variable names.
3131 getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,
3232
3333 /// Sets the value of a variable.
34 setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
34 setVariable: extern fn ([*:0]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
3535
3636 getNextHighMonotonicCount: usize, // TODO
3737
lib/std/os/uefi/tables/system_table.zig+1-1
......@@ -19,7 +19,7 @@ pub const SystemTable = extern struct {
1919 hdr: TableHeader,
2020
2121 /// A null-terminated string that identifies the vendor that produces the system firmware of the platform.
22 firmware_vendor: [*]u16,
22 firmware_vendor: [*:0]u16,
2323 firmware_revision: u32,
2424 console_in_handle: ?Handle,
2525 con_in: ?*SimpleTextInputProtocol,
lib/std/os/windows.zig+16-16
......@@ -60,7 +60,7 @@ pub fn CreateFile(
6060}
6161
6262pub fn CreateFileW(
63 file_path_w: [*]const u16,
63 file_path_w: [*:0]const u16,
6464 desired_access: DWORD,
6565 share_mode: DWORD,
6666 lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,
......@@ -425,8 +425,8 @@ pub fn CreateSymbolicLink(
425425}
426426
427427pub fn CreateSymbolicLinkW(
428 sym_link_path: [*]const u16,
429 target_path: [*]const u16,
428 sym_link_path: [*:0]const u16,
429 target_path: [*:0]const u16,
430430 flags: DWORD,
431431) CreateSymbolicLinkError!void {
432432 if (kernel32.CreateSymbolicLinkW(sym_link_path, target_path, flags) == 0) {
......@@ -449,7 +449,7 @@ pub fn DeleteFile(filename: []const u8) DeleteFileError!void {
449449 return DeleteFileW(&filename_w);
450450}
451451
452pub fn DeleteFileW(filename: [*]const u16) DeleteFileError!void {
452pub fn DeleteFileW(filename: [*:0]const u16) DeleteFileError!void {
453453 if (kernel32.DeleteFileW(filename) == 0) {
454454 switch (kernel32.GetLastError()) {
455455 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
471471 return MoveFileExW(&old_path_w, &new_path_w, flags);
472472}
473473
474pub fn MoveFileExW(old_path: [*]const u16, new_path: [*]const u16, flags: DWORD) MoveFileError!void {
474pub fn MoveFileExW(old_path: [*:0]const u16, new_path: [*:0]const u16, flags: DWORD) MoveFileError!void {
475475 if (kernel32.MoveFileExW(old_path, new_path, flags) == 0) {
476476 switch (kernel32.GetLastError()) {
477477 else => |err| return unexpectedError(err),
......@@ -490,7 +490,7 @@ pub fn CreateDirectory(pathname: []const u8, attrs: ?*SECURITY_ATTRIBUTES) Creat
490490 return CreateDirectoryW(&pathname_w, attrs);
491491}
492492
493pub fn CreateDirectoryW(pathname: [*]const u16, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void {
493pub fn CreateDirectoryW(pathname: [*:0]const u16, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void {
494494 if (kernel32.CreateDirectoryW(pathname, attrs) == 0) {
495495 switch (kernel32.GetLastError()) {
496496 ERROR.ALREADY_EXISTS => return error.PathAlreadyExists,
......@@ -511,7 +511,7 @@ pub fn RemoveDirectory(dir_path: []const u8) RemoveDirectoryError!void {
511511 return RemoveDirectoryW(&dir_path_w);
512512}
513513
514pub fn RemoveDirectoryW(dir_path_w: [*]const u16) RemoveDirectoryError!void {
514pub fn RemoveDirectoryW(dir_path_w: [*:0]const u16) RemoveDirectoryError!void {
515515 if (kernel32.RemoveDirectoryW(dir_path_w) == 0) {
516516 switch (kernel32.GetLastError()) {
517517 ERROR.PATH_NOT_FOUND => return error.FileNotFound,
......@@ -602,7 +602,7 @@ pub fn GetFinalPathNameByHandleW(
602602 buf_ptr: [*]u16,
603603 buf_len: DWORD,
604604 flags: DWORD,
605) GetFinalPathNameByHandleError!DWORD {
605) GetFinalPathNameByHandleError![:0]u16 {
606606 const rc = kernel32.GetFinalPathNameByHandleW(hFile, buf_ptr, buf_len, flags);
607607 if (rc == 0) {
608608 switch (kernel32.GetLastError()) {
......@@ -614,7 +614,7 @@ pub fn GetFinalPathNameByHandleW(
614614 else => |err| return unexpectedError(err),
615615 }
616616 }
617 return rc;
617 return buf_ptr[0..rc :0];
618618}
619619
620620pub const GetFileSizeError = error{Unexpected};
......@@ -640,7 +640,7 @@ pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD {
640640 return GetFileAttributesW(&filename_w);
641641}
642642
643pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD {
643pub fn GetFileAttributesW(lpFileName: [*:0]const u16) GetFileAttributesError!DWORD {
644644 const rc = kernel32.GetFileAttributesW(lpFileName);
645645 if (rc == INVALID_FILE_ATTRIBUTES) {
646646 switch (kernel32.GetLastError()) {
......@@ -733,14 +733,14 @@ pub fn WSAIoctl(
733733
734734const GetModuleFileNameError = error{Unexpected};
735735
736pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 {
736pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![:0]u16 {
737737 const rc = kernel32.GetModuleFileNameW(hModule, buf_ptr, buf_len);
738738 if (rc == 0) {
739739 switch (kernel32.GetLastError()) {
740740 else => |err| return unexpectedError(err),
741741 }
742742 }
743 return buf_ptr[0..rc];
743 return buf_ptr[0..rc :0];
744744}
745745
746746pub const TerminateProcessError = error{Unexpected};
......@@ -779,11 +779,11 @@ pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetCon
779779
780780pub const GetEnvironmentStringsError = error{OutOfMemory};
781781
782pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*]u16 {
782pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*:0]u16 {
783783 return kernel32.GetEnvironmentStringsW() orelse return error.OutOfMemory;
784784}
785785
786pub fn FreeEnvironmentStringsW(penv: [*]u16) void {
786pub fn FreeEnvironmentStringsW(penv: [*:0]u16) void {
787787 assert(kernel32.FreeEnvironmentStringsW(penv) != 0);
788788}
789789
......@@ -792,7 +792,7 @@ pub const GetEnvironmentVariableError = error{
792792 Unexpected,
793793};
794794
795pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) GetEnvironmentVariableError!DWORD {
795pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) GetEnvironmentVariableError!DWORD {
796796 const rc = kernel32.GetEnvironmentVariableW(lpName, lpBuffer, nSize);
797797 if (rc == 0) {
798798 switch (kernel32.GetLastError()) {
......@@ -850,7 +850,7 @@ pub const LoadLibraryError = error{
850850 Unexpected,
851851};
852852
853pub fn LoadLibraryW(lpLibFileName: [*]const u16) LoadLibraryError!HMODULE {
853pub fn LoadLibraryW(lpLibFileName: [*:0]const u16) LoadLibraryError!HMODULE {
854854 return kernel32.LoadLibraryW(lpLibFileName) orelse {
855855 switch (kernel32.GetLastError()) {
856856 ERROR.FILE_NOT_FOUND => return error.FileNotFound,
lib/std/os/windows/bits.zig+6-6
......@@ -33,17 +33,17 @@ pub const FARPROC = *@OpaqueType();
3333pub const INT = c_int;
3434pub const LPBYTE = *BYTE;
3535pub const LPCH = *CHAR;
36pub const LPCSTR = [*]const CHAR;
37pub const LPCTSTR = [*]const TCHAR;
36pub const LPCSTR = [*:0]const CHAR;
37pub const LPCTSTR = [*:0]const TCHAR;
3838pub const LPCVOID = *const c_void;
3939pub const LPDWORD = *DWORD;
40pub const LPSTR = [*]CHAR;
40pub const LPSTR = [*:0]CHAR;
4141pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
4242pub const LPVOID = *c_void;
43pub const LPWSTR = [*]WCHAR;
44pub const LPCWSTR = [*]const WCHAR;
43pub const LPWSTR = [*:0]WCHAR;
44pub const LPCWSTR = [*:0]const WCHAR;
4545pub const PVOID = *c_void;
46pub const PWSTR = [*]WCHAR;
46pub const PWSTR = [*:0]WCHAR;
4747pub const SIZE_T = usize;
4848pub const TCHAR = if (UNICODE) WCHAR else u8;
4949pub const UINT = c_uint;
lib/std/os/windows/kernel32.zig+13-13
......@@ -7,7 +7,7 @@ pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVE
77
88pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;
99
10pub extern "kernel32" stdcallcc fn CreateDirectoryW(lpPathName: [*]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) BOOL;
10pub extern "kernel32" stdcallcc fn CreateDirectoryW(lpPathName: [*:0]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) BOOL;
1111
1212pub extern "kernel32" stdcallcc fn CreateEventExW(
1313 lpEventAttributes: ?*SECURITY_ATTRIBUTES,
......@@ -17,7 +17,7 @@ pub extern "kernel32" stdcallcc fn CreateEventExW(
1717) ?HANDLE;
1818
1919pub extern "kernel32" stdcallcc fn CreateFileW(
20 lpFileName: [*]const u16, // TODO null terminated pointer type
20 lpFileName: [*:0]const u16,
2121 dwDesiredAccess: DWORD,
2222 dwShareMode: DWORD,
2323 lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,
......@@ -46,7 +46,7 @@ pub extern "kernel32" stdcallcc fn CreateProcessW(
4646 lpProcessInformation: *PROCESS_INFORMATION,
4747) BOOL;
4848
49pub extern "kernel32" stdcallcc fn CreateSymbolicLinkW(lpSymlinkFileName: [*]const u16, lpTargetFileName: [*]const u16, dwFlags: DWORD) BOOLEAN;
49pub extern "kernel32" stdcallcc fn CreateSymbolicLinkW(lpSymlinkFileName: [*:0]const u16, lpTargetFileName: [*:0]const u16, dwFlags: DWORD) BOOLEAN;
5050
5151pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) ?HANDLE;
5252
......@@ -63,19 +63,19 @@ pub extern "kernel32" stdcallcc fn DeviceIoControl(
6363 lpOverlapped: ?*OVERLAPPED,
6464) BOOL;
6565
66pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL;
66pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*:0]const u16) BOOL;
6767
6868pub extern "kernel32" stdcallcc fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) BOOL;
6969
7070pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn;
7171
72pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*]const u16, lpFindFileData: *WIN32_FIND_DATAW) HANDLE;
72pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*:0]const u16, lpFindFileData: *WIN32_FIND_DATAW) HANDLE;
7373pub extern "kernel32" stdcallcc fn FindClose(hFindFile: HANDLE) BOOL;
7474pub extern "kernel32" stdcallcc fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) BOOL;
7575
76pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) DWORD;
76pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: [*]u16, nSize: DWORD, Arguments: ?*va_list) DWORD;
7777
78pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*]u16) BOOL;
78pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*:0]u16) BOOL;
7979
8080pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;
8181
......@@ -88,9 +88,9 @@ pub extern "kernel32" stdcallcc fn GetCurrentDirectoryW(nBufferLength: DWORD, lp
8888pub extern "kernel32" stdcallcc fn GetCurrentThread() HANDLE;
8989pub extern "kernel32" stdcallcc fn GetCurrentThreadId() DWORD;
9090
91pub extern "kernel32" stdcallcc fn GetEnvironmentStringsW() ?[*]u16;
91pub extern "kernel32" stdcallcc fn GetEnvironmentStringsW() ?[*:0]u16;
9292
93pub extern "kernel32" stdcallcc fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) DWORD;
93pub extern "kernel32" stdcallcc fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) DWORD;
9494
9595pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) BOOL;
9696
......@@ -150,8 +150,8 @@ pub extern "kernel32" stdcallcc fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE
150150pub extern "kernel32" stdcallcc fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) BOOL;
151151
152152pub extern "kernel32" stdcallcc fn MoveFileExW(
153 lpExistingFileName: [*]const u16,
154 lpNewFileName: [*]const u16,
153 lpExistingFileName: [*:0]const u16,
154 lpNewFileName: [*:0]const u16,
155155 dwFlags: DWORD,
156156) BOOL;
157157
......@@ -180,7 +180,7 @@ pub extern "kernel32" stdcallcc fn ReadFile(
180180 in_out_lpOverlapped: ?*OVERLAPPED,
181181) BOOL;
182182
183pub extern "kernel32" stdcallcc fn RemoveDirectoryW(lpPathName: [*]const u16) BOOL;
183pub extern "kernel32" stdcallcc fn RemoveDirectoryW(lpPathName: [*:0]const u16) BOOL;
184184
185185pub extern "kernel32" stdcallcc fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) BOOL;
186186
......@@ -234,7 +234,7 @@ pub extern "kernel32" stdcallcc fn WriteFile(
234234
235235pub extern "kernel32" stdcallcc fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) BOOL;
236236
237pub extern "kernel32" stdcallcc fn LoadLibraryW(lpLibFileName: [*]const u16) ?HMODULE;
237pub extern "kernel32" stdcallcc fn LoadLibraryW(lpLibFileName: [*:0]const u16) ?HMODULE;
238238
239239pub extern "kernel32" stdcallcc fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) ?FARPROC;
240240
lib/std/os/windows/ntdll.zig+2-2
......@@ -35,9 +35,9 @@ pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile(
3535) NTSTATUS;
3636pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS;
3737pub extern "NtDll" stdcallcc fn RtlDosPathNameToNtPathName_U(
38 DosPathName: [*]const u16,
38 DosPathName: [*:0]const u16,
3939 NtPathName: *UNICODE_STRING,
40 NtFileNamePart: ?*?[*]const u16,
40 NtFileNamePart: ?*?[*:0]const u16,
4141 DirectoryInfo: ?*CURDIR,
4242) BOOL;
4343pub extern "NtDll" stdcallcc fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) void;
lib/std/os/windows/shell32.zig+1-1
......@@ -1,3 +1,3 @@
11usingnamespace @import("bits.zig");
22
3pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT;
3pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*:0]WCHAR) HRESULT;
lib/std/unicode.zig+2-3
......@@ -544,8 +544,7 @@ test "utf16leToUtf8" {
544544 }
545545}
546546
547/// TODO type for null terminated pointer
548pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![]u16 {
547pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![:0]u16 {
549548 var result = std.ArrayList(u16).init(allocator);
550549 // optimistically guess that it will not require surrogate pairs
551550 try result.ensureCapacity(utf8.len + 1);
......@@ -567,7 +566,7 @@ pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![]u16
567566 }
568567
569568 try result.append(0);
570 return result.toOwnedSlice();
569 return result.toOwnedSlice()[0..:0];
571570}
572571
573572/// Returns index of next character. If exact fit, returned index equals output slice length.