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

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

This commit is contained in:
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

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')
if s.str == 0 {
$if android {
C.fprintf(C.stdout, c'println(NIL)\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)
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)
}
}