Change cast syntax, int(x), []byte(s), (^int)(p)

This commit is contained in:
Ginger Bill
2017-01-17 23:36:07 +00:00
parent 367d307dc4
commit 2af9fb79dc
17 changed files with 529 additions and 356 deletions
+32 -32
View File
@@ -73,7 +73,7 @@ open :: proc(path: string, mode: int, perm: u32) -> (Handle, Errno) {
access |= FILE_APPEND_DATA;
}
share_mode := (FILE_SHARE_READ|FILE_SHARE_WRITE) as u32;
share_mode := u32(FILE_SHARE_READ|FILE_SHARE_WRITE);
sa: ^SECURITY_ATTRIBUTES = nil;
sa_inherit := SECURITY_ATTRIBUTES{length = size_of(SECURITY_ATTRIBUTES), inherit_handle = 1};
if mode&O_CLOEXEC == 0 {
@@ -95,38 +95,38 @@ open :: proc(path: string, mode: int, perm: u32) -> (Handle, Errno) {
}
buf: [300]byte;
copy(buf[:], path as []byte);
copy(buf[:], []byte(path));
handle := CreateFileA(^buf[0], access, share_mode, sa, create_mode, FILE_ATTRIBUTE_NORMAL, nil) as Handle;
handle := Handle(CreateFileA(^buf[0], access, share_mode, sa, create_mode, FILE_ATTRIBUTE_NORMAL, nil));
if handle != INVALID_HANDLE {
return handle, ERROR_NONE;
}
err := GetLastError();
return INVALID_HANDLE, err as Errno;
return INVALID_HANDLE, Errno(err);
}
close :: proc(fd: Handle) {
win32.CloseHandle(fd as win32.HANDLE);
win32.CloseHandle(win32.HANDLE(fd));
}
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
bytes_written: i32;
e := win32.WriteFile(fd as win32.HANDLE, data.data, data.count as i32, ^bytes_written, nil);
e := win32.WriteFile(win32.HANDLE(fd), data.data, i32(data.count), ^bytes_written, nil);
if e == win32.FALSE {
err := win32.GetLastError();
return 0, err as Errno;
return 0, Errno(err);
}
return bytes_written as int, ERROR_NONE;
return int(bytes_written), ERROR_NONE;
}
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
bytes_read: i32;
e := win32.ReadFile(fd as win32.HANDLE, data.data, data.count as u32, ^bytes_read, nil);
e := win32.ReadFile(win32.HANDLE(fd), data.data, u32(data.count), ^bytes_read, nil);
if e == win32.FALSE {
err := win32.GetLastError();
return 0, err as Errno;
return 0, Errno(err);
}
return bytes_read as int, ERROR_NONE;
return int(bytes_read), ERROR_NONE;
}
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
@@ -137,18 +137,18 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
case 1: w = FILE_CURRENT;
case 2: w = FILE_END;
}
hi := (offset>>32) as i32;
lo := offset as i32;
ft := GetFileType(fd as HANDLE);
hi := i32(offset>>32);
lo := i32(offset);
ft := GetFileType(HANDLE(fd));
if ft == FILE_TYPE_PIPE {
return 0, ERROR_FILE_IS_PIPE;
}
dw_ptr := SetFilePointer(fd as HANDLE, lo, ^hi, w);
dw_ptr := SetFilePointer(HANDLE(fd), lo, ^hi, w);
if dw_ptr == INVALID_SET_FILE_POINTER {
err := GetLastError();
return 0, err as Errno;
return 0, Errno(err);
}
return (hi as i64)<<32 + (dw_ptr as i64), ERROR_NONE;
return i64(hi)<<32 + i64(dw_ptr), ERROR_NONE;
}
@@ -159,9 +159,9 @@ stderr := get_std_handle(win32.STD_ERROR_HANDLE);
get_std_handle :: proc(h: int) -> Handle {
fd := win32.GetStdHandle(h as i32);
fd := win32.GetStdHandle(i32(h));
win32.SetHandleInformation(fd, win32.HANDLE_FLAG_INHERIT, 0);
return fd as Handle;
return Handle(fd);
}
@@ -171,9 +171,9 @@ get_std_handle :: proc(h: int) -> Handle {
last_write_time :: proc(fd: Handle) -> File_Time {
file_info: win32.BY_HANDLE_FILE_INFORMATION;
win32.GetFileInformationByHandle(fd as win32.HANDLE, ^file_info);
lo := file_info.last_write_time.lo as File_Time;
hi := file_info.last_write_time.hi as File_Time;
win32.GetFileInformationByHandle(win32.HANDLE(fd), ^file_info);
lo := File_Time(file_info.last_write_time.lo);
hi := File_Time(file_info.last_write_time.hi);
return lo | hi << 32;
}
@@ -184,14 +184,14 @@ last_write_time_by_name :: proc(name: string) -> File_Time {
assert(buf.count > name.count);
copy(buf[:], name as []byte);
copy(buf[:], []byte(name));
if win32.GetFileAttributesExA(^buf[0], win32.GetFileExInfoStandard, ^data) != 0 {
last_write_time = data.last_write_time;
}
l := last_write_time.lo as File_Time;
h := last_write_time.hi as File_Time;
l := File_Time(last_write_time.lo);
h := File_Time(last_write_time.hi);
return l | h << 32;
}
@@ -201,7 +201,7 @@ last_write_time_by_name :: proc(name: string) -> File_Time {
read_entire_file :: proc(name: string) -> ([]byte, bool) {
buf: [300]byte;
copy(buf[:], name as []byte);
copy(buf[:], []byte(name));
fd, err := open(name, O_RDONLY, 0);
if err != ERROR_NONE {
@@ -210,7 +210,7 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
defer close(fd);
length: i64;
file_size_ok := win32.GetFileSizeEx(fd as win32.HANDLE, ^length) != 0;
file_size_ok := win32.GetFileSizeEx(win32.HANDLE(fd), ^length) != 0;
if !file_size_ok {
return nil, false;
}
@@ -228,18 +228,18 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
to_read: u32;
MAX :: 1<<32-1;
if remaining <= MAX {
to_read = remaining as u32;
to_read = u32(remaining);
} else {
to_read = MAX;
}
win32.ReadFile(fd as win32.HANDLE, ^data[total_read], to_read, ^single_read_length, nil);
win32.ReadFile(win32.HANDLE(fd), ^data[total_read], to_read, ^single_read_length, nil);
if single_read_length <= 0 {
free(data.data);
return nil, false;
}
total_read += single_read_length as i64;
total_read += i64(single_read_length);
}
return data, true;
@@ -259,14 +259,14 @@ heap_free :: proc(ptr: rawptr) {
exit :: proc(code: int) {
win32.ExitProcess(code as u32);
win32.ExitProcess(u32(code));
}
current_thread_id :: proc() -> int {
GetCurrentThreadId :: proc() -> u32 #foreign #dll_import
return GetCurrentThreadId() as int;
return int(GetCurrentThreadId());
}