Skip to content

Commit

Permalink
builtin: add support for -d bultin_writeln_should_write_at_once and…
Browse files Browse the repository at this point in the history
… `-d bultin_write_buf_to_fd_should_use_c_write` (#19243)
  • Loading branch information
spytheman committed Aug 30, 2023
1 parent 7927583 commit 803001e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vlib/builtin/builtin.c.v
Expand Up @@ -262,6 +262,12 @@ pub fn println(s string) {

[manualfree]
fn _writeln_to_fd(fd int, s string) {
$if !bultin_writeln_should_write_at_once ? {
lf := u8(`\n`)
_write_buf_to_fd(fd, s.str, s.len)
_write_buf_to_fd(fd, &lf, 1)
return
}
unsafe {
buf_len := s.len + 1 // space for \n
mut buf := malloc(buf_len)
Expand All @@ -282,7 +288,7 @@ fn _write_buf_to_fd(fd int, buf &u8, buf_len int) {
mut ptr := unsafe { buf }
mut remaining_bytes := isize(buf_len)
mut x := isize(0)
$if freestanding || vinix {
$if freestanding || vinix || bultin_write_buf_to_fd_should_use_c_write ? {
unsafe {
for remaining_bytes > 0 {
x = C.write(fd, ptr, remaining_bytes)
Expand Down

0 comments on commit 803001e

Please sign in to comment.