mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: optimize os_windows.v
This commit is contained in:
parent
adb1d3f8c9
commit
9d2a60bb11
@ -51,6 +51,18 @@ fn test_open_file() {
|
|||||||
os.rm(filename)
|
os.rm(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_create_file() {
|
||||||
|
filename := './test1.txt'
|
||||||
|
hello := 'hello world!'
|
||||||
|
mut f := os.create(filename) or { panic(err)}
|
||||||
|
f.write(hello)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
assert hello.len == os.file_size(filename)
|
||||||
|
|
||||||
|
os.rm(filename)
|
||||||
|
}
|
||||||
|
|
||||||
fn test_write_and_read_string_to_file() {
|
fn test_write_and_read_string_to_file() {
|
||||||
filename := './test1.txt'
|
filename := './test1.txt'
|
||||||
hello := 'hello world!'
|
hello := 'hello world!'
|
||||||
|
@ -135,27 +135,20 @@ pub fn is_dir(path string) bool {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn open(path string) ?File {
|
pub fn open(path string) ?File {
|
||||||
mut file := File{}
|
file := File {
|
||||||
wpath := path.to_wide()
|
cfile: C._wfopen(path.to_wide(), 'rb'.to_wide())
|
||||||
mode := 'rb'
|
opened: true
|
||||||
file = File{
|
|
||||||
cfile: C._wfopen(wpath, mode.to_wide())
|
|
||||||
}
|
}
|
||||||
if isnil(file.cfile) {
|
if isnil(file.cfile) {
|
||||||
return error('failed to open file "$path"')
|
return error('failed to open file "$path"')
|
||||||
}
|
}
|
||||||
file.opened = true
|
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// create creates a file at a specified location and returns a writable `File` object.
|
// create creates a file at a specified location and returns a writable `File` object.
|
||||||
pub fn create(path string) ?File {
|
pub fn create(path string) ?File {
|
||||||
wpath := path.replace('/', '\\').to_wide()
|
file := File {
|
||||||
mode := 'wb'
|
cfile: C._wfopen(path.to_wide(), 'wb'.to_wide())
|
||||||
file := File{
|
|
||||||
cfile: C._wfopen(wpath, mode.to_wide())
|
|
||||||
opened: true
|
opened: true
|
||||||
}
|
}
|
||||||
if isnil(file.cfile) {
|
if isnil(file.cfile) {
|
||||||
|
Loading…
Reference in New Issue
Block a user