diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index 7e5b06dc81..4f22e1e7f6 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -235,7 +235,7 @@ fn C.WideCharToMultiByte() int fn C._wstat() -fn C._wrename() +fn C._wrename() int fn C._wfopen() voidptr diff --git a/vlib/os/os_c.v b/vlib/os/os_c.v index d006096f21..f457b82ae8 100644 --- a/vlib/os/os_c.v +++ b/vlib/os/os_c.v @@ -114,7 +114,7 @@ pub fn file_size(path string) int { } // mv moves files or folders from `src` to `dst`. -pub fn mv(src string, dst string) { +pub fn mv(src string, dst string) ? { mut rdst := dst if is_dir(rdst) { rdst = join_path(rdst.trim_right(path_separator), file_name(src.trim_right(path_separator))) @@ -122,9 +122,15 @@ pub fn mv(src string, dst string) { $if windows { w_src := src.replace('/', '\\') w_dst := rdst.replace('/', '\\') - C._wrename(w_src.to_wide(), w_dst.to_wide()) + ret := C._wrename(w_src.to_wide(), w_dst.to_wide()) + if ret != 0 { + return error_with_code('failed to rename $src to $dst', int(ret)) + } } $else { - C.rename(charptr(src.str), charptr(rdst.str)) + ret := C.rename(charptr(src.str), charptr(rdst.str)) + if ret != 0 { + return error_with_code('failed to rename $src to $dst', int(ret)) + } } }