mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
351b2e0e42
commit
190f5c69ea
@ -101,7 +101,12 @@ pub fn open_file(path string, mode string, options ...int) !File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
p := fix_windows_path(path)
|
p := fix_windows_path(path)
|
||||||
fd := C.open(&char(p.str), flags, permission)
|
mut fd := 0
|
||||||
|
$if windows {
|
||||||
|
fd = C._wopen(p.to_wide(), flags, permission)
|
||||||
|
} $else {
|
||||||
|
fd = C.open(&char(p.str), flags, permission)
|
||||||
|
}
|
||||||
if fd == -1 {
|
if fd == -1 {
|
||||||
return error(posix_get_error_msg(C.errno))
|
return error(posix_get_error_msg(C.errno))
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ fn test_open_file_wb_ab() {
|
|||||||
mut afile := os.open_file('text.txt', 'ab', 0o666)!
|
mut afile := os.open_file('text.txt', 'ab', 0o666)!
|
||||||
afile.write_string('hello')!
|
afile.write_string('hello')!
|
||||||
afile.close()
|
afile.close()
|
||||||
assert os.read_file('text.txt')? == 'hellohello'
|
assert os.read_file('text.txt')! == 'hellohello'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_open_append() {
|
fn test_open_append() {
|
||||||
@ -438,3 +438,14 @@ fn test_open_append() {
|
|||||||
f3.close()
|
f3.close()
|
||||||
assert os.read_lines(tfile)! == ['abc', 'abc', 'def']
|
assert os.read_lines(tfile)! == ['abc', 'abc', 'def']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_open_file_on_chinese_windows() {
|
||||||
|
$if windows {
|
||||||
|
os.rm('中文.txt') or {}
|
||||||
|
mut f1 := os.open_file('中文.txt', 'w+', 0x666) or { panic(err) }
|
||||||
|
f1.write_string('test')!
|
||||||
|
f1.close()
|
||||||
|
|
||||||
|
assert os.read_file('中文.txt')! == 'test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -19,6 +19,8 @@ fn C.sigaction(int, voidptr, int) int
|
|||||||
|
|
||||||
fn C.open(&char, int, ...int) int
|
fn C.open(&char, int, ...int) int
|
||||||
|
|
||||||
|
fn C._wopen(&u16, int, ...int) int
|
||||||
|
|
||||||
fn C.fdopen(fd int, mode &char) &C.FILE
|
fn C.fdopen(fd int, mode &char) &C.FILE
|
||||||
|
|
||||||
fn C.ferror(stream &C.FILE) int
|
fn C.ferror(stream &C.FILE) int
|
||||||
|
Loading…
Reference in New Issue
Block a user