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

builtin: use C.fwrite (buffered) for _write_buf_to_fd (#14558)

This commit is contained in:
Delyan Angelov
2022-05-30 19:15:05 +03:00
committed by GitHub
parent 58ebc0680e
commit 0f3b2c2ae7
11 changed files with 69 additions and 14 deletions

View File

@@ -268,13 +268,28 @@ fn _write_buf_to_fd(fd int, buf &u8, buf_len int) {
if buf_len <= 0 {
return
}
unsafe {
mut ptr := buf
mut remaining_bytes := buf_len
for remaining_bytes > 0 {
x := C.write(fd, ptr, remaining_bytes)
ptr += x
remaining_bytes -= x
mut ptr := unsafe { buf }
mut remaining_bytes := isize(buf_len)
mut x := isize(0)
$if freestanding || vinix {
unsafe {
for remaining_bytes > 0 {
x = C.write(fd, ptr, remaining_bytes)
ptr += x
remaining_bytes -= x
}
}
} $else {
mut stream := voidptr(C.stdout)
if fd == 2 {
stream = voidptr(C.stderr)
}
unsafe {
for remaining_bytes > 0 {
x = isize(C.fwrite(ptr, 1, remaining_bytes, stream))
ptr += x
remaining_bytes -= x
}
}
}
}