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

os: fix os.read_file and os.read_bytes for 0 sized /proc/ files on Linux (fix #15852) (#15853)

This commit is contained in:
Dominik Pytlewski
2022-09-25 21:54:46 +02:00
committed by GitHub
parent 50820105a1
commit 721328ef58
4 changed files with 126 additions and 35 deletions

View File

@ -16,6 +16,17 @@ pub fn new_builder(initial_size int) Builder {
return res
}
// reuse_as_plain_u8_array allows using the Builder instance as a plain []u8 return value.
// It is useful, when you have accumulated data in the builder, that you want to
// pass/access as []u8 later, without copying or freeing the buffer.
// NB: you *should NOT use* the string builder instance after calling this method.
// Use only the return value after calling this method.
[unsafe]
pub fn (mut b Builder) reuse_as_plain_u8_array() []u8 {
unsafe { b.flags.clear(.noslices) }
return *b
}
// write_ptr writes `len` bytes provided byteptr to the accumulated buffer
[unsafe]
pub fn (mut b Builder) write_ptr(ptr &u8, len int) {