1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: deprecate os.File.write_bytes and add os.File.write_ptr (#9370)

This commit is contained in:
zakuro
2021-03-20 16:02:28 +09:00
committed by GitHub
parent ead0dff55a
commit e3c0f305b2
10 changed files with 41 additions and 15 deletions

View File

@ -218,17 +218,36 @@ pub fn (mut f File) write_to(pos int, buf []byte) ?int {
// write_bytes writes `size` bytes to the file, starting from the address in `data`.
// NB: write_bytes is unsafe and should be used carefully, since if you pass invalid
// pointers to it, it will cause your programs to segfault.
[deprecated: 'use File.write_ptr()']
[unsafe]
pub fn (mut f File) write_bytes(data voidptr, size int) int {
return int(C.fwrite(data, 1, size, f.cfile))
return unsafe { f.write_ptr(data, size) }
}
// write_bytes_at writes `size` bytes to the file, starting from the address in `data`,
// at byte offset `pos`, counting from the start of the file (pos 0).
// NB: write_bytes_at is unsafe and should be used carefully, since if you pass invalid
// pointers to it, it will cause your programs to segfault.
[deprecated: 'use File.write_ptr_at() instead']
[unsafe]
pub fn (mut f File) write_bytes_at(data voidptr, size int, pos int) int {
return unsafe { f.write_ptr_at(data, size, pos) }
}
// write_ptr writes `size` bytes to the file, starting from the address in `data`.
// NB: write_ptr is unsafe and should be used carefully, since if you pass invalid
// pointers to it, it will cause your programs to segfault.
[unsafe]
pub fn (mut f File) write_ptr(data voidptr, size int) int {
return int(C.fwrite(data, 1, size, f.cfile))
}
// write_ptr_at writes `size` bytes to the file, starting from the address in `data`,
// at byte offset `pos`, counting from the start of the file (pos 0).
// NB: write_ptr_at is unsafe and should be used carefully, since if you pass invalid
// pointers to it, it will cause your programs to segfault.
[unsafe]
pub fn (mut f File) write_ptr_at(data voidptr, size int, pos int) int {
C.fseek(f.cfile, pos, C.SEEK_SET)
res := int(C.fwrite(data, 1, size, f.cfile))
C.fseek(f.cfile, 0, C.SEEK_END)