authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-07 16:13:34-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-07 16:13:34-05:00
log7b73c7fe12e96de1be92b27474048566244f98c4
treeca5d8811921d113bfbfeb88721e4635d904d0762
parente2e9be5deac75e102bc5faaa94aa17308224f9f6
parent2662e50d27006396a4b6c776dc757e883b836fcc
signature Commit is signed but in an unrecognized format.

Merge branch 'std-utf16-sentinel-terminated' of https://github.com/daurnimator/zig


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

lib/std/child_process.zig+2-4
...@@ -582,9 +582,7 @@ pub const ChildProcess = struct {...@@ -582,9 +582,7 @@ pub const ChildProcess = struct {
582 };582 };
583 var piProcInfo: windows.PROCESS_INFORMATION = undefined;583 var piProcInfo: windows.PROCESS_INFORMATION = undefined;
584584
585 const cwd_slice = if (self.cwd) |cwd| try cstr.addNullByte(self.allocator, cwd) else null;585 const cwd_w = if (self.cwd) |cwd| try unicode.utf8ToUtf16LeWithNull(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;
588 defer if (cwd_w) |cwd| self.allocator.free(cwd);586 defer if (cwd_w) |cwd| self.allocator.free(cwd);
589 const cwd_w_ptr = if (cwd_w) |cwd| cwd.ptr else null;587 const cwd_w_ptr = if (cwd_w) |cwd| cwd.ptr else null;
590588
...@@ -701,7 +699,7 @@ pub const ChildProcess = struct {...@@ -701,7 +699,7 @@ pub const ChildProcess = struct {
701 }699 }
702};700};
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 {
705 // TODO the docs for environment pointer say:703 // TODO the docs for environment pointer say:
706 // > A pointer to the environment block for the new process. If this parameter704 // > A pointer to the environment block for the new process. If this parameter
707 // > is NULL, the new process uses the environment of the calling process.705 // > 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 {...@@ -60,7 +60,7 @@ pub const File = struct {
60 }60 }
6161
62 /// Deprecated; call `std.fs.Dir.openFileW` directly.62 /// 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 {
64 return std.fs.cwd().openFileW(path_w, .{});64 return std.fs.cwd().openFileW(path_w, .{});
65 }65 }
6666
lib/std/fs/get_app_data_dir.zig+2-8
...@@ -15,7 +15,7 @@ pub const GetAppDataDirError = error{...@@ -15,7 +15,7 @@ pub const GetAppDataDirError = error{
15pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataDirError![]u8 {15pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataDirError![]u8 {
16 switch (builtin.os) {16 switch (builtin.os) {
17 .windows => {17 .windows => {
18 var dir_path_ptr: [*]u16 = undefined;18 var dir_path_ptr: [*:0]u16 = undefined;
19 switch (os.windows.shell32.SHGetKnownFolderPath(19 switch (os.windows.shell32.SHGetKnownFolderPath(
20 &os.windows.FOLDERID_LocalAppData,20 &os.windows.FOLDERID_LocalAppData,
21 os.windows.KF_FLAG_CREATE,21 os.windows.KF_FLAG_CREATE,
...@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
24 )) {24 )) {
25 os.windows.S_OK => {25 os.windows.S_OK => {
26 defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr));26 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) {
28 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,28 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
29 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,29 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
30 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,30 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,
...@@ -55,12 +55,6 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -55,12 +55,6 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
55 }55 }
56}56}
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
64test "getAppDataDir" {58test "getAppDataDir" {
65 var buf: [512]u8 = undefined;59 var buf: [512]u8 = undefined;
66 const allocator = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator;60 const allocator = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator;
lib/std/os.zig+1-3
...@@ -2632,9 +2632,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real...@@ -2632,9 +2632,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real
2632 defer windows.CloseHandle(h_file);2632 defer windows.CloseHandle(h_file);
26332633
2634 var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;2634 var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;
2635 const wide_len = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS);2635 const wide_slice = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS);
2636 assert(wide_len <= wide_buf.len);
2637 const wide_slice = wide_buf[0..wide_len];
26382636
2639 // Windows returns \\?\ prepended to the path.2637 // Windows returns \\?\ prepended to the path.
2640 // We strip it to make this function consistent across platforms.2638 // 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;...@@ -4,8 +4,8 @@ const Guid = uefi.Guid;
4/// Character output devices4/// Character output devices
5pub const SimpleTextOutputProtocol = extern struct {5pub const SimpleTextOutputProtocol = extern struct {
6 _reset: extern fn (*const SimpleTextOutputProtocol, bool) usize,6 _reset: extern fn (*const SimpleTextOutputProtocol, bool) usize,
7 _output_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, [*]const u16) usize,8 _test_string: extern fn (*const SimpleTextOutputProtocol, [*:0]const u16) usize,
9 _query_mode: extern fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) usize,9 _query_mode: extern fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) usize,
10 _set_mode: extern fn (*const SimpleTextOutputProtocol, usize) usize,10 _set_mode: extern fn (*const SimpleTextOutputProtocol, usize) usize,
11 _set_attribute: extern fn (*const SimpleTextOutputProtocol, usize) usize,11 _set_attribute: extern fn (*const SimpleTextOutputProtocol, usize) usize,
...@@ -20,12 +20,12 @@ pub const SimpleTextOutputProtocol = extern struct {...@@ -20,12 +20,12 @@ pub const SimpleTextOutputProtocol = extern struct {
20 }20 }
2121
22 /// Writes a string to the output device.22 /// 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 {
24 return self._output_string(self, msg);24 return self._output_string(self, msg);
25 }25 }
2626
27 /// Verifies that all characters in a string can be output to the target device.27 /// 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 {
29 return self._test_string(self, msg);29 return self._test_string(self, msg);
30 }30 }
3131
lib/std/os/uefi/tables/runtime_services.zig+2-2
...@@ -25,13 +25,13 @@ pub const RuntimeServices = extern struct {...@@ -25,13 +25,13 @@ pub const RuntimeServices = extern struct {
25 convertPointer: usize, // TODO25 convertPointer: usize, // TODO
2626
27 /// Returns the value of a variable.27 /// 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
30 /// Enumerates the current variable names.30 /// Enumerates the current variable names.
31 getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,31 getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,
3232
33 /// Sets the value of a variable.33 /// 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
36 getNextHighMonotonicCount: usize, // TODO36 getNextHighMonotonicCount: usize, // TODO
3737
lib/std/os/uefi/tables/system_table.zig+1-1
...@@ -19,7 +19,7 @@ pub const SystemTable = extern struct {...@@ -19,7 +19,7 @@ pub const SystemTable = extern struct {
19 hdr: TableHeader,19 hdr: TableHeader,
2020
21 /// A null-terminated string that identifies the vendor that produces the system firmware of the platform.21 /// 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,
23 firmware_revision: u32,23 firmware_revision: u32,
24 console_in_handle: ?Handle,24 console_in_handle: ?Handle,
25 con_in: ?*SimpleTextInputProtocol,25 con_in: ?*SimpleTextInputProtocol,
lib/std/os/windows.zig+16-16
...@@ -60,7 +60,7 @@ pub fn CreateFile(...@@ -60,7 +60,7 @@ pub fn CreateFile(
60}60}
6161
62pub fn CreateFileW(62pub fn CreateFileW(
63 file_path_w: [*]const u16,63 file_path_w: [*:0]const u16,
64 desired_access: DWORD,64 desired_access: DWORD,
65 share_mode: DWORD,65 share_mode: DWORD,
66 lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,66 lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,
...@@ -425,8 +425,8 @@ pub fn CreateSymbolicLink(...@@ -425,8 +425,8 @@ pub fn CreateSymbolicLink(
425}425}
426426
427pub fn CreateSymbolicLinkW(427pub fn CreateSymbolicLinkW(
428 sym_link_path: [*]const u16,428 sym_link_path: [*:0]const u16,
429 target_path: [*]const u16,429 target_path: [*:0]const u16,
430 flags: DWORD,430 flags: DWORD,
431) CreateSymbolicLinkError!void {431) CreateSymbolicLinkError!void {
432 if (kernel32.CreateSymbolicLinkW(sym_link_path, target_path, flags) == 0) {432 if (kernel32.CreateSymbolicLinkW(sym_link_path, target_path, flags) == 0) {
...@@ -449,7 +449,7 @@ pub fn DeleteFile(filename: []const u8) DeleteFileError!void {...@@ -449,7 +449,7 @@ pub fn DeleteFile(filename: []const u8) DeleteFileError!void {
449 return DeleteFileW(&filename_w);449 return DeleteFileW(&filename_w);
450}450}
451451
452pub fn DeleteFileW(filename: [*]const u16) DeleteFileError!void {452pub fn DeleteFileW(filename: [*:0]const u16) DeleteFileError!void {
453 if (kernel32.DeleteFileW(filename) == 0) {453 if (kernel32.DeleteFileW(filename) == 0) {
454 switch (kernel32.GetLastError()) {454 switch (kernel32.GetLastError()) {
455 ERROR.FILE_NOT_FOUND => return error.FileNotFound,455 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...@@ -471,7 +471,7 @@ pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) Move
471 return MoveFileExW(&old_path_w, &new_path_w, flags);471 return MoveFileExW(&old_path_w, &new_path_w, flags);
472}472}
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 {
475 if (kernel32.MoveFileExW(old_path, new_path, flags) == 0) {475 if (kernel32.MoveFileExW(old_path, new_path, flags) == 0) {
476 switch (kernel32.GetLastError()) {476 switch (kernel32.GetLastError()) {
477 else => |err| return unexpectedError(err),477 else => |err| return unexpectedError(err),
...@@ -490,7 +490,7 @@ pub fn CreateDirectory(pathname: []const u8, attrs: ?*SECURITY_ATTRIBUTES) Creat...@@ -490,7 +490,7 @@ pub fn CreateDirectory(pathname: []const u8, attrs: ?*SECURITY_ATTRIBUTES) Creat
490 return CreateDirectoryW(&pathname_w, attrs);490 return CreateDirectoryW(&pathname_w, attrs);
491}491}
492492
493pub fn CreateDirectoryW(pathname: [*]const u16, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void {493pub fn CreateDirectoryW(pathname: [*:0]const u16, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void {
494 if (kernel32.CreateDirectoryW(pathname, attrs) == 0) {494 if (kernel32.CreateDirectoryW(pathname, attrs) == 0) {
495 switch (kernel32.GetLastError()) {495 switch (kernel32.GetLastError()) {
496 ERROR.ALREADY_EXISTS => return error.PathAlreadyExists,496 ERROR.ALREADY_EXISTS => return error.PathAlreadyExists,
...@@ -511,7 +511,7 @@ pub fn RemoveDirectory(dir_path: []const u8) RemoveDirectoryError!void {...@@ -511,7 +511,7 @@ pub fn RemoveDirectory(dir_path: []const u8) RemoveDirectoryError!void {
511 return RemoveDirectoryW(&dir_path_w);511 return RemoveDirectoryW(&dir_path_w);
512}512}
513513
514pub fn RemoveDirectoryW(dir_path_w: [*]const u16) RemoveDirectoryError!void {514pub fn RemoveDirectoryW(dir_path_w: [*:0]const u16) RemoveDirectoryError!void {
515 if (kernel32.RemoveDirectoryW(dir_path_w) == 0) {515 if (kernel32.RemoveDirectoryW(dir_path_w) == 0) {
516 switch (kernel32.GetLastError()) {516 switch (kernel32.GetLastError()) {
517 ERROR.PATH_NOT_FOUND => return error.FileNotFound,517 ERROR.PATH_NOT_FOUND => return error.FileNotFound,
...@@ -602,7 +602,7 @@ pub fn GetFinalPathNameByHandleW(...@@ -602,7 +602,7 @@ pub fn GetFinalPathNameByHandleW(
602 buf_ptr: [*]u16,602 buf_ptr: [*]u16,
603 buf_len: DWORD,603 buf_len: DWORD,
604 flags: DWORD,604 flags: DWORD,
605) GetFinalPathNameByHandleError!DWORD {605) GetFinalPathNameByHandleError![:0]u16 {
606 const rc = kernel32.GetFinalPathNameByHandleW(hFile, buf_ptr, buf_len, flags);606 const rc = kernel32.GetFinalPathNameByHandleW(hFile, buf_ptr, buf_len, flags);
607 if (rc == 0) {607 if (rc == 0) {
608 switch (kernel32.GetLastError()) {608 switch (kernel32.GetLastError()) {
...@@ -614,7 +614,7 @@ pub fn GetFinalPathNameByHandleW(...@@ -614,7 +614,7 @@ pub fn GetFinalPathNameByHandleW(
614 else => |err| return unexpectedError(err),614 else => |err| return unexpectedError(err),
615 }615 }
616 }616 }
617 return rc;617 return buf_ptr[0..rc :0];
618}618}
619619
620pub const GetFileSizeError = error{Unexpected};620pub const GetFileSizeError = error{Unexpected};
...@@ -640,7 +640,7 @@ pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD {...@@ -640,7 +640,7 @@ pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD {
640 return GetFileAttributesW(&filename_w);640 return GetFileAttributesW(&filename_w);
641}641}
642642
643pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD {643pub fn GetFileAttributesW(lpFileName: [*:0]const u16) GetFileAttributesError!DWORD {
644 const rc = kernel32.GetFileAttributesW(lpFileName);644 const rc = kernel32.GetFileAttributesW(lpFileName);
645 if (rc == INVALID_FILE_ATTRIBUTES) {645 if (rc == INVALID_FILE_ATTRIBUTES) {
646 switch (kernel32.GetLastError()) {646 switch (kernel32.GetLastError()) {
...@@ -733,14 +733,14 @@ pub fn WSAIoctl(...@@ -733,14 +733,14 @@ pub fn WSAIoctl(
733733
734const GetModuleFileNameError = error{Unexpected};734const 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 {
737 const rc = kernel32.GetModuleFileNameW(hModule, buf_ptr, buf_len);737 const rc = kernel32.GetModuleFileNameW(hModule, buf_ptr, buf_len);
738 if (rc == 0) {738 if (rc == 0) {
739 switch (kernel32.GetLastError()) {739 switch (kernel32.GetLastError()) {
740 else => |err| return unexpectedError(err),740 else => |err| return unexpectedError(err),
741 }741 }
742 }742 }
743 return buf_ptr[0..rc];743 return buf_ptr[0..rc :0];
744}744}
745745
746pub const TerminateProcessError = error{Unexpected};746pub const TerminateProcessError = error{Unexpected};
...@@ -779,11 +779,11 @@ pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetCon...@@ -779,11 +779,11 @@ pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetCon
779779
780pub const GetEnvironmentStringsError = error{OutOfMemory};780pub const GetEnvironmentStringsError = error{OutOfMemory};
781781
782pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*]u16 {782pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*:0]u16 {
783 return kernel32.GetEnvironmentStringsW() orelse return error.OutOfMemory;783 return kernel32.GetEnvironmentStringsW() orelse return error.OutOfMemory;
784}784}
785785
786pub fn FreeEnvironmentStringsW(penv: [*]u16) void {786pub fn FreeEnvironmentStringsW(penv: [*:0]u16) void {
787 assert(kernel32.FreeEnvironmentStringsW(penv) != 0);787 assert(kernel32.FreeEnvironmentStringsW(penv) != 0);
788}788}
789789
...@@ -792,7 +792,7 @@ pub const GetEnvironmentVariableError = error{...@@ -792,7 +792,7 @@ pub const GetEnvironmentVariableError = error{
792 Unexpected,792 Unexpected,
793};793};
794794
795pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) GetEnvironmentVariableError!DWORD {795pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) GetEnvironmentVariableError!DWORD {
796 const rc = kernel32.GetEnvironmentVariableW(lpName, lpBuffer, nSize);796 const rc = kernel32.GetEnvironmentVariableW(lpName, lpBuffer, nSize);
797 if (rc == 0) {797 if (rc == 0) {
798 switch (kernel32.GetLastError()) {798 switch (kernel32.GetLastError()) {
...@@ -850,7 +850,7 @@ pub const LoadLibraryError = error{...@@ -850,7 +850,7 @@ pub const LoadLibraryError = error{
850 Unexpected,850 Unexpected,
851};851};
852852
853pub fn LoadLibraryW(lpLibFileName: [*]const u16) LoadLibraryError!HMODULE {853pub fn LoadLibraryW(lpLibFileName: [*:0]const u16) LoadLibraryError!HMODULE {
854 return kernel32.LoadLibraryW(lpLibFileName) orelse {854 return kernel32.LoadLibraryW(lpLibFileName) orelse {
855 switch (kernel32.GetLastError()) {855 switch (kernel32.GetLastError()) {
856 ERROR.FILE_NOT_FOUND => return error.FileNotFound,856 ERROR.FILE_NOT_FOUND => return error.FileNotFound,
lib/std/os/windows/bits.zig+6-6
...@@ -33,17 +33,17 @@ pub const FARPROC = *@OpaqueType();...@@ -33,17 +33,17 @@ pub const FARPROC = *@OpaqueType();
33pub const INT = c_int;33pub const INT = c_int;
34pub const LPBYTE = *BYTE;34pub const LPBYTE = *BYTE;
35pub const LPCH = *CHAR;35pub const LPCH = *CHAR;
36pub const LPCSTR = [*]const CHAR;36pub const LPCSTR = [*:0]const CHAR;
37pub const LPCTSTR = [*]const TCHAR;37pub const LPCTSTR = [*:0]const TCHAR;
38pub const LPCVOID = *const c_void;38pub const LPCVOID = *const c_void;
39pub const LPDWORD = *DWORD;39pub const LPDWORD = *DWORD;
40pub const LPSTR = [*]CHAR;40pub const LPSTR = [*:0]CHAR;
41pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;41pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
42pub const LPVOID = *c_void;42pub const LPVOID = *c_void;
43pub const LPWSTR = [*]WCHAR;43pub const LPWSTR = [*:0]WCHAR;
44pub const LPCWSTR = [*]const WCHAR;44pub const LPCWSTR = [*:0]const WCHAR;
45pub const PVOID = *c_void;45pub const PVOID = *c_void;
46pub const PWSTR = [*]WCHAR;46pub const PWSTR = [*:0]WCHAR;
47pub const SIZE_T = usize;47pub const SIZE_T = usize;
48pub const TCHAR = if (UNICODE) WCHAR else u8;48pub const TCHAR = if (UNICODE) WCHAR else u8;
49pub const UINT = c_uint;49pub const UINT = c_uint;
lib/std/os/windows/kernel32.zig+13-13
...@@ -7,7 +7,7 @@ pub extern "kernel32" fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) c...@@ -7,7 +7,7 @@ pub extern "kernel32" fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) c
77
8pub extern "kernel32" fn CloseHandle(hObject: HANDLE) callconv(.Stdcall) BOOL;8pub extern "kernel32" fn CloseHandle(hObject: HANDLE) callconv(.Stdcall) BOOL;
99
10pub extern "kernel32" fn CreateDirectoryW(lpPathName: [*]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) callconv(.Stdcall) BOOL;10pub extern "kernel32" fn CreateDirectoryW(lpPathName: [*:0]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) callconv(.Stdcall) BOOL;
1111
12pub extern "kernel32" fn CreateEventExW(12pub extern "kernel32" fn CreateEventExW(
13 lpEventAttributes: ?*SECURITY_ATTRIBUTES,13 lpEventAttributes: ?*SECURITY_ATTRIBUTES,
...@@ -17,7 +17,7 @@ pub extern "kernel32" fn CreateEventExW(...@@ -17,7 +17,7 @@ pub extern "kernel32" fn CreateEventExW(
17) callconv(.Stdcall) ?HANDLE;17) callconv(.Stdcall) ?HANDLE;
1818
19pub extern "kernel32" fn CreateFileW(19pub extern "kernel32" fn CreateFileW(
20 lpFileName: [*]const u16, // TODO null terminated pointer type20 lpFileName: [*:0]const u16,
21 dwDesiredAccess: DWORD,21 dwDesiredAccess: DWORD,
22 dwShareMode: DWORD,22 dwShareMode: DWORD,
23 lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,23 lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,
...@@ -46,7 +46,7 @@ pub extern "kernel32" fn CreateProcessW(...@@ -46,7 +46,7 @@ pub extern "kernel32" fn CreateProcessW(
46 lpProcessInformation: *PROCESS_INFORMATION,46 lpProcessInformation: *PROCESS_INFORMATION,
47) callconv(.Stdcall) BOOL;47) callconv(.Stdcall) BOOL;
4848
49pub extern "kernel32" fn CreateSymbolicLinkW(lpSymlinkFileName: [*]const u16, lpTargetFileName: [*]const u16, dwFlags: DWORD) callconv(.Stdcall) BOOLEAN;49pub extern "kernel32" fn CreateSymbolicLinkW(lpSymlinkFileName: [*:0]const u16, lpTargetFileName: [*:0]const u16, dwFlags: DWORD) callconv(.Stdcall) BOOLEAN;
5050
51pub extern "kernel32" fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) callconv(.Stdcall) ?HANDLE;51pub extern "kernel32" fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) callconv(.Stdcall) ?HANDLE;
5252
...@@ -63,19 +63,19 @@ pub extern "kernel32" fn DeviceIoControl(...@@ -63,19 +63,19 @@ pub extern "kernel32" fn DeviceIoControl(
63 lpOverlapped: ?*OVERLAPPED,63 lpOverlapped: ?*OVERLAPPED,
64) callconv(.Stdcall) BOOL;64) callconv(.Stdcall) BOOL;
6565
66pub extern "kernel32" fn DeleteFileW(lpFileName: [*]const u16) callconv(.Stdcall) BOOL;66pub extern "kernel32" fn DeleteFileW(lpFileName: [*:0]const u16) callconv(.Stdcall) BOOL;
6767
68pub extern "kernel32" fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) callconv(.Stdcall) BOOL;68pub extern "kernel32" fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) callconv(.Stdcall) BOOL;
6969
70pub extern "kernel32" fn ExitProcess(exit_code: UINT) callconv(.Stdcall) noreturn;70pub extern "kernel32" fn ExitProcess(exit_code: UINT) callconv(.Stdcall) noreturn;
7171
72pub extern "kernel32" fn FindFirstFileW(lpFileName: [*]const u16, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) HANDLE;72pub extern "kernel32" fn FindFirstFileW(lpFileName: [*:0]const u16, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) HANDLE;
73pub extern "kernel32" fn FindClose(hFindFile: HANDLE) callconv(.Stdcall) BOOL;73pub extern "kernel32" fn FindClose(hFindFile: HANDLE) callconv(.Stdcall) BOOL;
74pub extern "kernel32" fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) BOOL;74pub extern "kernel32" fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) BOOL;
7575
76pub extern "kernel32" fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) callconv(.Stdcall) DWORD;76pub extern "kernel32" fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: [*]u16, nSize: DWORD, Arguments: ?*va_list) callconv(.Stdcall) DWORD;
7777
78pub extern "kernel32" fn FreeEnvironmentStringsW(penv: [*]u16) callconv(.Stdcall) BOOL;78pub extern "kernel32" fn FreeEnvironmentStringsW(penv: [*:0]u16) callconv(.Stdcall) BOOL;
7979
80pub extern "kernel32" fn GetCommandLineA() callconv(.Stdcall) LPSTR;80pub extern "kernel32" fn GetCommandLineA() callconv(.Stdcall) LPSTR;
8181
...@@ -88,9 +88,9 @@ pub extern "kernel32" fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: ?[...@@ -88,9 +88,9 @@ pub extern "kernel32" fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: ?[
88pub extern "kernel32" fn GetCurrentThread() callconv(.Stdcall) HANDLE;88pub extern "kernel32" fn GetCurrentThread() callconv(.Stdcall) HANDLE;
89pub extern "kernel32" fn GetCurrentThreadId() callconv(.Stdcall) DWORD;89pub extern "kernel32" fn GetCurrentThreadId() callconv(.Stdcall) DWORD;
9090
91pub extern "kernel32" fn GetEnvironmentStringsW() callconv(.Stdcall) ?[*]u16;91pub extern "kernel32" fn GetEnvironmentStringsW() callconv(.Stdcall) ?[*:0]u16;
9292
93pub extern "kernel32" fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) callconv(.Stdcall) DWORD;93pub extern "kernel32" fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) callconv(.Stdcall) DWORD;
9494
95pub extern "kernel32" fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) callconv(.Stdcall) BOOL;95pub extern "kernel32" fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) callconv(.Stdcall) BOOL;
9696
...@@ -150,8 +150,8 @@ pub extern "kernel32" fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE_T, flAllo...@@ -150,8 +150,8 @@ pub extern "kernel32" fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE_T, flAllo
150pub extern "kernel32" fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) callconv(.Stdcall) BOOL;150pub extern "kernel32" fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) callconv(.Stdcall) BOOL;
151151
152pub extern "kernel32" fn MoveFileExW(152pub extern "kernel32" fn MoveFileExW(
153 lpExistingFileName: [*]const u16,153 lpExistingFileName: [*:0]const u16,
154 lpNewFileName: [*]const u16,154 lpNewFileName: [*:0]const u16,
155 dwFlags: DWORD,155 dwFlags: DWORD,
156) callconv(.Stdcall) BOOL;156) callconv(.Stdcall) BOOL;
157157
...@@ -180,7 +180,7 @@ pub extern "kernel32" fn ReadFile(...@@ -180,7 +180,7 @@ pub extern "kernel32" fn ReadFile(
180 in_out_lpOverlapped: ?*OVERLAPPED,180 in_out_lpOverlapped: ?*OVERLAPPED,
181) callconv(.Stdcall) BOOL;181) callconv(.Stdcall) BOOL;
182182
183pub extern "kernel32" fn RemoveDirectoryW(lpPathName: [*]const u16) callconv(.Stdcall) BOOL;183pub extern "kernel32" fn RemoveDirectoryW(lpPathName: [*:0]const u16) callconv(.Stdcall) BOOL;
184184
185pub extern "kernel32" fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) callconv(.Stdcall) BOOL;185pub extern "kernel32" fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) callconv(.Stdcall) BOOL;
186186
...@@ -234,7 +234,7 @@ pub extern "kernel32" fn WriteFile(...@@ -234,7 +234,7 @@ pub extern "kernel32" fn WriteFile(
234234
235pub extern "kernel32" fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) callconv(.Stdcall) BOOL;235pub extern "kernel32" fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) callconv(.Stdcall) BOOL;
236236
237pub extern "kernel32" fn LoadLibraryW(lpLibFileName: [*]const u16) callconv(.Stdcall) ?HMODULE;237pub extern "kernel32" fn LoadLibraryW(lpLibFileName: [*:0]const u16) callconv(.Stdcall) ?HMODULE;
238238
239pub extern "kernel32" fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) callconv(.Stdcall) ?FARPROC;239pub extern "kernel32" fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) callconv(.Stdcall) ?FARPROC;
240240
lib/std/os/windows/ntdll.zig+2-2
...@@ -35,9 +35,9 @@ pub extern "NtDll" fn NtDeviceIoControlFile(...@@ -35,9 +35,9 @@ pub extern "NtDll" fn NtDeviceIoControlFile(
35) callconv(.Stdcall) NTSTATUS;35) callconv(.Stdcall) NTSTATUS;
36pub extern "NtDll" fn NtClose(Handle: HANDLE) callconv(.Stdcall) NTSTATUS;36pub extern "NtDll" fn NtClose(Handle: HANDLE) callconv(.Stdcall) NTSTATUS;
37pub extern "NtDll" fn RtlDosPathNameToNtPathName_U(37pub extern "NtDll" fn RtlDosPathNameToNtPathName_U(
38 DosPathName: [*]const u16,38 DosPathName: [*:0]const u16,
39 NtPathName: *UNICODE_STRING,39 NtPathName: *UNICODE_STRING,
40 NtFileNamePart: ?*?[*]const u16,40 NtFileNamePart: ?*?[*:0]const u16,
41 DirectoryInfo: ?*CURDIR,41 DirectoryInfo: ?*CURDIR,
42) callconv(.Stdcall) BOOL;42) callconv(.Stdcall) BOOL;
43pub extern "NtDll" fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) callconv(.Stdcall) void;43pub extern "NtDll" fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) callconv(.Stdcall) void;
lib/std/os/windows/shell32.zig+1-1
...@@ -1,3 +1,3 @@...@@ -1,3 +1,3 @@
1usingnamespace @import("bits.zig");1usingnamespace @import("bits.zig");
22
3pub extern "shell32" fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) callconv(.Stdcall) HRESULT;3pub extern "shell32" fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*:0]WCHAR) callconv(.Stdcall) HRESULT;
lib/std/unicode.zig+2-3
...@@ -544,8 +544,7 @@ test "utf16leToUtf8" {...@@ -544,8 +544,7 @@ test "utf16leToUtf8" {
544 }544 }
545}545}
546546
547/// TODO type for null terminated pointer547pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![:0]u16 {
548pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![]u16 {
549 var result = std.ArrayList(u16).init(allocator);548 var result = std.ArrayList(u16).init(allocator);
550 // optimistically guess that it will not require surrogate pairs549 // optimistically guess that it will not require surrogate pairs
551 try result.ensureCapacity(utf8.len + 1);550 try result.ensureCapacity(utf8.len + 1);
...@@ -567,7 +566,7 @@ pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![]u16...@@ -567,7 +566,7 @@ pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![]u16
567 }566 }
568567
569 try result.append(0);568 try result.append(0);
570 return result.toOwnedSlice();569 return result.toOwnedSlice()[0..:0];
571}570}
572571
573/// Returns index of next character. If exact fit, returned index equals output slice length.572/// Returns index of next character. If exact fit, returned index equals output slice length.