From 539e9712e545e837e41a8cb617c30c22ce08ee53 Mon Sep 17 00:00:00 2001 From: danyaberezun Date: Thu, 29 Feb 2024 15:30:23 +0200 Subject: [PATCH] add new function for debug in Lama: LprintfPerrror --- synonym for fprintf(perror,...) --- runtime/Std.i | 1 + runtime/runtime.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/runtime/Std.i b/runtime/Std.i index 8810f9db1..10ad1d2c1 100644 --- a/runtime/Std.i +++ b/runtime/Std.i @@ -23,6 +23,7 @@ F,regexpMatch; F,sprintf; F,makeString; F,printf; +F,printfPerror; F,fprintf; F,fopen; F,fclose; diff --git a/runtime/runtime.c b/runtime/runtime.c index 8bf2b7f6a..b37147a8b 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -987,6 +987,19 @@ extern void Lfailure (char *s, ...) { vfailure(s, args); } +extern void LprintfPerror (char *s, ...) { + va_list args = (va_list)BOX(NULL); + + ASSERT_STRING("printfPerror:1", s); + + va_start(args, s); + fix_unboxed(s, args); + + if (vfprintf(stderr, s, args) < 0) { failure("printfPerror (...): %s\n", strerror(errno)); } + + fflush(stderr); +} + extern void Bmatch_failure (void *v, char *fname, int line, int col) { createStringBuf(); printValue(v); @@ -1251,8 +1264,8 @@ extern void set_args (int argc, char *argv[]) { POST_GC(); global_sysargs = p; - global_stdout = stdout; - global_stderr = stderr; + global_stdout = stdout; + global_stderr = stderr; push_extra_root((void **)&global_sysargs); }