Add utf8_to_ucs2 for package win32 so that the wide procedures can used by default

This commit is contained in:
gingerBill
2018-08-30 10:59:46 +01:00
parent 6c18864291
commit 0858ae2024
4 changed files with 73 additions and 16 deletions
+2 -2
View File
@@ -67,8 +67,8 @@ read_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Errno) {
heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
size, alignment: int,
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
using mem.Allocator_Mode;
switch mode {
+4 -11
View File
@@ -98,11 +98,8 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errn
case:
create_mode = win32.OPEN_EXISTING;
}
buf: [300]byte;
copy(buf[:], cast([]byte)path);
handle := Handle(win32.create_file_a(cstring(&buf[0]), access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil));
wide_path := win32.utf8_to_wstring(path);
handle := Handle(win32.create_file_w(wide_path, access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil));
if handle != INVALID_HANDLE do return handle, ERROR_NONE;
err := Errno(win32.get_last_error());
@@ -217,13 +214,9 @@ last_write_time :: proc(fd: Handle) -> File_Time {
last_write_time_by_name :: proc(name: string) -> File_Time {
last_write_time: win32.Filetime;
data: win32.File_Attribute_Data;
buf: [1024]byte;
assert(len(buf) > len(name));
copy(buf[:], cast([]byte)name);
if win32.get_file_attributes_ex_a(cstring(&buf[0]), win32.GetFileExInfoStandard, &data) {
wide_path := win32.utf8_to_wstring(name);
if win32.get_file_attributes_ex_w(wide_path, win32.GetFileExInfoStandard, &data) {
last_write_time = data.last_write_time;
}