builtin: simplify println(), use C.write consistently on unix as on windows so that 0 bytes are output also

pull/9599/head
Delyan Angelov 2021-04-04 18:13:25 +03:00
parent f3484345c7
commit 824790a2bd
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 12 additions and 19 deletions

View File

@ -139,26 +139,19 @@ fn C.asl_log(voidptr, voidptr, int, charptr)
*/
// println prints a message with a line end, to stdout. stdout is flushed.
pub fn println(s string) {
$if windows {
print(s)
print('\n')
} $else {
// For debugging .app applications (no way to read stdout) so that it's printed to macOS Console
/*
$if macos {
C.asl_log(0, 0, C.ASL_LEVEL_ERR, s.str)
if s.str == 0 {
$if android {
C.fprintf(C.stdout, c'println(NIL)\n')
} $else {
C.write(1, c'println(NIL)\n', 13)
}
*/
// TODO: a syscall sys_write on linux works, except for the v repl.
// Probably it is a stdio buffering issue. Needs more testing...
// $if linux {
// $if !android {
// snl := s + '\n'
// C.syscall(/* sys_write */ 1, /* stdout_value */ 1, snl.str, s.len+1)
// return
// }
// }
C.printf('%.*s\n', s.len, s.str)
return
}
$if android {
C.fprintf(C.stdout, c'%.*s\n', s.len, s.str)
} $else {
C.write(1, s.str, s.len)
C.write(1, c'\n', 1)
}
}