mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: disable write_bytes_at() and read_bytes_at() for now
This commit is contained in:
parent
f9cc419dba
commit
4424f83470
14
vlib/os/os.v
14
vlib/os/os.v
@ -75,6 +75,7 @@ pub fn (f File) is_opened() bool {
|
||||
return f.opened
|
||||
}
|
||||
|
||||
/*
|
||||
// read_bytes reads an amount of bytes from the beginning of the file
|
||||
pub fn (f mut File) read_bytes(size int) []byte {
|
||||
return f.read_bytes_at(size, 0)
|
||||
@ -88,6 +89,7 @@ pub fn (f mut File) read_bytes_at(size, pos int) []byte {
|
||||
C.fseek(f.cfile, 0, C.SEEK_SET)
|
||||
return arr[0..nreadbytes]
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn read_bytes(path string) ?[]byte {
|
||||
mut fp := vfopen(path, 'rb')
|
||||
@ -295,14 +297,24 @@ pub fn open_append(path string) ?File {
|
||||
// for example if we have write(7, 4), "07 00 00 00" gets written
|
||||
// write(0x1234, 2) => "34 12"
|
||||
pub fn (f mut File) write_bytes(data voidptr, size int) {
|
||||
C.fwrite(data, 1, size, f.cfile)
|
||||
$if linux {
|
||||
C.syscall(sys_write, f.fd, data, 1)
|
||||
} $else {
|
||||
C.fwrite(data, 1, size, f.cfile)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn (f mut File) write_bytes_at(data voidptr, size, pos int) {
|
||||
$if linux {
|
||||
}
|
||||
$else {
|
||||
C.fseek(f.cfile, pos, C.SEEK_SET)
|
||||
C.fwrite(data, 1, size, f.cfile)
|
||||
C.fseek(f.cfile, 0, C.SEEK_END)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
pub fn (f mut File) flush() {
|
||||
|
@ -124,6 +124,11 @@ pub fn create(path string) ?File {
|
||||
return file
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn (f mut File) fseek(pos, mode int) {
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn (f mut File) write(s string) {
|
||||
if !f.opened {
|
||||
return
|
||||
|
@ -1,7 +1,8 @@
|
||||
import os
|
||||
|
||||
fn test_aaa_setup(){
|
||||
cleanup_leftovers() assert true
|
||||
cleanup_leftovers()
|
||||
assert true
|
||||
}
|
||||
|
||||
fn test_setenv() {
|
||||
@ -39,6 +40,7 @@ fn test_write_and_read_string_to_file() {
|
||||
|
||||
// test_write_and_read_bytes checks for regressions made in the functions
|
||||
// read_bytes, read_bytes_at and write_bytes.
|
||||
/*
|
||||
fn test_write_and_read_bytes() {
|
||||
file_name := './byte_reader_writer.tst'
|
||||
payload := [`I`, `D`, `D`, `Q`, `D`]
|
||||
@ -72,6 +74,7 @@ fn test_write_and_read_bytes() {
|
||||
// We finally delete the test file.
|
||||
os.rm(file_name)
|
||||
}
|
||||
*/
|
||||
|
||||
fn test_create_and_delete_folder() {
|
||||
folder := './test1'
|
||||
@ -219,6 +222,18 @@ fn test_zzz_cleanup(){
|
||||
cleanup_leftovers() assert true
|
||||
}
|
||||
|
||||
|
||||
fn test_symlink() {
|
||||
$if windows { return }
|
||||
os.mkdir('symlink') or { panic(err) }
|
||||
os.symlink('symlink', 'symlink2') or { panic(err) }
|
||||
assert os.exists('symlink2')
|
||||
|
||||
// cleanup
|
||||
os.rm('symlink')
|
||||
os.rm('symlink2')
|
||||
}
|
||||
|
||||
// this function is called by both test_aaa_setup & test_zzz_cleanup
|
||||
// it ensures that os tests do not polute the filesystem with leftover
|
||||
// files so that they can be run several times in a row.
|
||||
@ -237,14 +252,3 @@ fn cleanup_leftovers(){
|
||||
os.rm('ex1.txt')
|
||||
os.rm('ex2.txt')
|
||||
}
|
||||
|
||||
fn test_symlink() {
|
||||
$if windows { return }
|
||||
os.mkdir('symlink') or { panic(err) }
|
||||
os.symlink('symlink', 'symlink2') or { panic(err) }
|
||||
assert os.exists('symlink2')
|
||||
|
||||
// cleanup
|
||||
os.rm('symlink')
|
||||
os.rm('symlink2')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user