From 07a1a9b84de14c4a81e47c7caa81317617b41d53 Mon Sep 17 00:00:00 2001 From: Larpon Date: Fri, 5 Mar 2021 18:12:42 +0100 Subject: [PATCH] builtin: use fprintf to print to stderr on Android (#9130) --- vlib/builtin/builtin.c.v | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/vlib/builtin/builtin.c.v b/vlib/builtin/builtin.c.v index 1a59ef180a..a0a1ebd14f 100644 --- a/vlib/builtin/builtin.c.v +++ b/vlib/builtin/builtin.c.v @@ -80,11 +80,19 @@ pub fn eprintln(s string) { C.fflush(C.stdout) C.fflush(C.stderr) // eprintln is used in panics, so it should not fail at all - if s.str == 0 { - C.write(2, c'eprintln(NIL)\n', 14) - } else { - C.write(2, s.str, s.len) - C.write(2, c'\n', 1) + $if android { + if s.str == 0 { + C.fprintf(C.stderr, c'eprintln(NIL)\n') + } else { + C.fprintf(C.stderr, c'%.*s\n', s.len, s.str) + } + } $else { + if s.str == 0 { + C.write(2, c'eprintln(NIL)\n', 14) + } else { + C.write(2, s.str, s.len) + C.write(2, c'\n', 1) + } } C.fflush(C.stderr) } @@ -93,10 +101,18 @@ pub fn eprintln(s string) { pub fn eprint(s string) { C.fflush(C.stdout) C.fflush(C.stderr) - if s.str == 0 { - C.write(2, c'eprint(NIL)\n', 12) - } else { - C.write(2, s.str, s.len) + $if android { + if s.str == 0 { + C.fprintf(C.stderr, c'eprint(NIL)') + } else { + C.fprintf(C.stderr, c'%.*s', s.len, s.str) + } + } $else { + if s.str == 0 { + C.write(2, c'eprint(NIL)', 11) + } else { + C.write(2, s.str, s.len) + } } C.fflush(C.stderr) } @@ -104,7 +120,11 @@ pub fn eprint(s string) { // print prints a message to stdout. Unlike `println` stdout is not automatically flushed. // A call to `flush()` will flush the output buffer to stdout. pub fn print(s string) { - C.write(1, s.str, s.len) + $if android { + C.fprintf(C.stdout, c'%.*s', s.len, s.str) + } $else { + C.write(1, s.str, s.len) + } } /*