mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: windows fixes
This commit is contained in:
parent
cfd4f0c69c
commit
1f93bb5a9a
@ -42,5 +42,6 @@
|
|||||||
+ bare metal support
|
+ bare metal support
|
||||||
+ inline assembly
|
+ inline assembly
|
||||||
+ x64 machine code generation (ELF)
|
+ x64 machine code generation (ELF)
|
||||||
|
- require implicit C.fn definitions, add all missing definitions
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,12 +130,13 @@ pub fn dir_exists(path string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn C.CreateDirectory(byteptr, int) bool
|
||||||
|
|
||||||
// mkdir creates a new directory with the specified path.
|
// mkdir creates a new directory with the specified path.
|
||||||
pub fn mkdir(path string) ?bool {
|
pub fn mkdir(path string) ?bool {
|
||||||
if path == '.' { return true }
|
if path == '.' { return true }
|
||||||
apath := os.realpath( path )
|
apath := os.realpath( path )
|
||||||
r := int(C.CreateDirectory(apath.to_wide(), 0))
|
if !C.CreateDirectory(apath.to_wide(), 0) {
|
||||||
if r == 0 {
|
|
||||||
return error('mkdir failed for "$apath", because CreateDirectory returned ' + get_error_msg(int(C.GetLastError())))
|
return error('mkdir failed for "$apath", because CreateDirectory returned ' + get_error_msg(int(C.GetLastError())))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -237,13 +238,14 @@ pub fn exec(cmd string) ?Result {
|
|||||||
sa.nLength = sizeof(C.SECURITY_ATTRIBUTES)
|
sa.nLength = sizeof(C.SECURITY_ATTRIBUTES)
|
||||||
sa.bInheritHandle = true
|
sa.bInheritHandle = true
|
||||||
|
|
||||||
create_pipe_result := int(C.CreatePipe(voidptr(&child_stdout_read), voidptr(&child_stdout_write), voidptr(&sa), 0))
|
create_pipe_ok := C.CreatePipe(voidptr(&child_stdout_read),
|
||||||
if create_pipe_result == 0 {
|
voidptr(&child_stdout_write), voidptr(&sa), 0)
|
||||||
|
if !create_pipe_ok {
|
||||||
error_msg := get_error_msg(int(C.GetLastError()))
|
error_msg := get_error_msg(int(C.GetLastError()))
|
||||||
return error('exec failed (CreatePipe): $error_msg')
|
return error('exec failed (CreatePipe): $error_msg')
|
||||||
}
|
}
|
||||||
set_handle_info_result := int(C.SetHandleInformation(child_stdout_read, C.HANDLE_FLAG_INHERIT, 0))
|
set_handle_info_ok := C.SetHandleInformation(child_stdout_read, C.HANDLE_FLAG_INHERIT, 0)
|
||||||
if set_handle_info_result == 0 {
|
if !set_handle_info_ok {
|
||||||
error_msg := get_error_msg(int(C.GetLastError()))
|
error_msg := get_error_msg(int(C.GetLastError()))
|
||||||
panic('exec failed (SetHandleInformation): $error_msg')
|
panic('exec failed (SetHandleInformation): $error_msg')
|
||||||
}
|
}
|
||||||
@ -257,8 +259,8 @@ pub fn exec(cmd string) ?Result {
|
|||||||
start_info.dwFlags = u32(C.STARTF_USESTDHANDLES)
|
start_info.dwFlags = u32(C.STARTF_USESTDHANDLES)
|
||||||
command_line := [32768]u16
|
command_line := [32768]u16
|
||||||
C.ExpandEnvironmentStringsW(cmd.to_wide(), voidptr(&command_line), 32768)
|
C.ExpandEnvironmentStringsW(cmd.to_wide(), voidptr(&command_line), 32768)
|
||||||
create_process_result := int(C.CreateProcessW(0, command_line, 0, 0, C.TRUE, 0, 0, 0, voidptr(&start_info), voidptr(&proc_info)))
|
create_process_ok := C.CreateProcessW(0, command_line, 0, 0, C.TRUE, 0, 0, 0, voidptr(&start_info), voidptr(&proc_info))
|
||||||
if create_process_result == 0 {
|
if !create_process_ok {
|
||||||
error_msg := get_error_msg(int(C.GetLastError()))
|
error_msg := get_error_msg(int(C.GetLastError()))
|
||||||
return error('exec failed (CreateProcess): $error_msg')
|
return error('exec failed (CreateProcess): $error_msg')
|
||||||
}
|
}
|
||||||
@ -270,7 +272,7 @@ pub fn exec(cmd string) ?Result {
|
|||||||
for {
|
for {
|
||||||
readfile_result := C.ReadFile(child_stdout_read, buf, 1000, voidptr(&bytes_read), 0)
|
readfile_result := C.ReadFile(child_stdout_read, buf, 1000, voidptr(&bytes_read), 0)
|
||||||
read_data += tos(buf, int(bytes_read))
|
read_data += tos(buf, int(bytes_read))
|
||||||
if (readfile_result == false || int(bytes_read) == 0) {
|
if readfile_result == false || int(bytes_read) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user