diff options
Diffstat (limited to '')
-rw-r--r-- | common/ttyio.c | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/common/ttyio.c b/common/ttyio.c index fd748009e..c77b4a85a 100644 --- a/common/ttyio.c +++ b/common/ttyio.c @@ -219,11 +219,58 @@ tty_printf( const char *fmt, ... ) } +/* Same as tty_printf but if FP is not NULL, behave like a regualr + fprintf. */ +void +tty_fprintf (FILE *fp, const char *fmt, ... ) +{ + va_list arg_ptr; + + if (fp) + { + va_start (arg_ptr, fmt) ; + vfprintf (fp, fmt, arg_ptr ); + va_end (arg_ptr); + return; + } + + if (no_terminal) + return; + + if( !initialized ) + init_ttyfp(); + + va_start( arg_ptr, fmt ) ; +#ifdef __MINGW32__ + { + char *buf = NULL; + int n; + DWORD nwritten; + + n = vasprintf(&buf, fmt, arg_ptr); + if( !buf ) + log_bug("vasprintf() failed\n"); + + if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) ) + log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() ); + if( n != nwritten ) + log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten ); + last_prompt_len += n; + xfree (buf); + } +#else + last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ; + fflush(ttyfp); +#endif + va_end(arg_ptr); +} + + /**************** * Print a string, but filter all control characters out. */ void -tty_print_string( byte *p, size_t n ) +tty_print_string ( const byte *p, size_t n ) { if (no_terminal) return; @@ -261,7 +308,7 @@ tty_print_string( byte *p, size_t n ) } void -tty_print_utf8_string2( byte *p, size_t n, size_t max_n ) +tty_print_utf8_string2( const byte *p, size_t n, size_t max_n ) { size_t i; char *buf; @@ -292,7 +339,7 @@ tty_print_utf8_string2( byte *p, size_t n, size_t max_n ) } void -tty_print_utf8_string( byte *p, size_t n ) +tty_print_utf8_string( const byte *p, size_t n ) { tty_print_utf8_string2( p, n, 0 ); } |