mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix truncate() on windows (#18262)
This commit is contained in:
@@ -147,13 +147,17 @@ pub fn read_file(path string) !string {
|
||||
// truncate changes the size of the file located in `path` to `len`.
|
||||
// Note that changing symbolic links on Windows only works as admin.
|
||||
pub fn truncate(path string, len u64) ! {
|
||||
fp := C.open(&char(path.str), o_wronly | o_trunc, 0)
|
||||
defer {
|
||||
C.close(fp)
|
||||
fp := $if windows {
|
||||
C._wopen(path.to_wide(), o_wronly | o_trunc, 0)
|
||||
} $else {
|
||||
C.open(&char(path.str), o_wronly | o_trunc, 0)
|
||||
}
|
||||
if fp < 0 {
|
||||
return error_with_code(posix_get_error_msg(C.errno), C.errno)
|
||||
}
|
||||
defer {
|
||||
C.close(fp)
|
||||
}
|
||||
$if windows {
|
||||
if C._chsize_s(fp, len) != 0 {
|
||||
return error_with_code(posix_get_error_msg(C.errno), C.errno)
|
||||
|
||||
Reference in New Issue
Block a user