os: tag some File methods that take voidptr as unsafe - write_bytes, write_bytes_at (#8985)
parent
0b3f209965
commit
aed348fb80
|
@ -78,7 +78,7 @@ fn main() {
|
||||||
println('ERR: $err')
|
println('ERR: $err')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
wrote := file.write_bytes(data, size)
|
wrote := unsafe { file.write_bytes(data, size) }
|
||||||
println('write_bytes: $wrote [./google.pdf]')
|
println('write_bytes: $wrote [./google.pdf]')
|
||||||
file.flush()
|
file.flush()
|
||||||
file.close()
|
file.close()
|
||||||
|
|
|
@ -79,10 +79,12 @@ pub fn (mut f File) write_to(pos int, buf []byte) ?int {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[unsafe]
|
||||||
pub fn (mut f File) write_bytes(data voidptr, size int) int {
|
pub fn (mut f File) write_bytes(data voidptr, size int) int {
|
||||||
return int(C.fwrite(data, 1, size, f.cfile))
|
return int(C.fwrite(data, 1, size, f.cfile))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[unsafe]
|
||||||
pub fn (mut f File) write_bytes_at(data voidptr, size int, pos int) int {
|
pub fn (mut f File) write_bytes_at(data voidptr, size int, pos int) int {
|
||||||
C.fseek(f.cfile, pos, C.SEEK_SET)
|
C.fseek(f.cfile, pos, C.SEEK_SET)
|
||||||
res := int(C.fwrite(data, 1, size, f.cfile))
|
res := int(C.fwrite(data, 1, size, f.cfile))
|
||||||
|
|
|
@ -325,7 +325,7 @@ pub fn write_file(path string, text string) ? {
|
||||||
// write_file_array writes the data in `buffer` to a file in `path`.
|
// write_file_array writes the data in `buffer` to a file in `path`.
|
||||||
pub fn write_file_array(path string, buffer array) ? {
|
pub fn write_file_array(path string, buffer array) ? {
|
||||||
mut f := create(path) ?
|
mut f := create(path) ?
|
||||||
f.write_bytes_at(buffer.data, (buffer.len * buffer.element_size), 0)
|
unsafe { f.write_bytes_at(buffer.data, (buffer.len * buffer.element_size), 0) }
|
||||||
f.close()
|
f.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ pub fn (mut g Gen) generate_elf_footer() {
|
||||||
// Create the binary
|
// Create the binary
|
||||||
mut f := os.create(g.out_name) or { panic(err) }
|
mut f := os.create(g.out_name) or { panic(err) }
|
||||||
os.chmod(g.out_name, 0o775) // make it an executable
|
os.chmod(g.out_name, 0o775) // make it an executable
|
||||||
f.write_bytes(g.buf.data, g.buf.len)
|
unsafe { f.write_bytes(g.buf.data, g.buf.len) }
|
||||||
f.close()
|
f.close()
|
||||||
println('\nx64 elf binary has been successfully generated')
|
println('\nx64 elf binary has been successfully generated')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue