mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: make rm
return an optional
This commit is contained in:
parent
7665114ded
commit
30169f86c1
@ -291,7 +291,7 @@ fn C._putenv() int
|
||||
fn C._waccess() int
|
||||
|
||||
|
||||
fn C._wremove()
|
||||
fn C._wremove() int
|
||||
|
||||
|
||||
fn C.ReadConsole() voidptr
|
||||
|
15
vlib/os/os.v
15
vlib/os/os.v
@ -628,12 +628,21 @@ pub fn file_exists(_path string) bool {
|
||||
}
|
||||
|
||||
// rm removes file in `path`.
|
||||
pub fn rm(path string) {
|
||||
pub fn rm(path string) ? {
|
||||
$if windows {
|
||||
C._wremove(path.to_wide())
|
||||
rc := C._wremove(path.to_wide())
|
||||
if rc == -1 {
|
||||
//TODO: proper error as soon as it's supported on windows
|
||||
return error('Failed to remove "$path"')
|
||||
}
|
||||
} $else {
|
||||
C.remove(path.str)
|
||||
rc := C.remove(path.str)
|
||||
if rc == -1 {
|
||||
return error(posix_get_error_msg(C.errno))
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
// C.unlink(path.cstr())
|
||||
}
|
||||
// rmdir removes a specified directory.
|
||||
|
Loading…
Reference in New Issue
Block a user