diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/getch2.c | 27 | ||||
-rw-r--r-- | osdep/io.c | 25 | ||||
-rw-r--r-- | osdep/io.h | 2 |
3 files changed, 43 insertions, 11 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c index 0cbaa82a25..f0aa19a2cc 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <signal.h> #include <sys/time.h> #include <sys/types.h> #ifdef CONFIG_IOCTL @@ -288,27 +289,41 @@ bool getch2(struct mp_fifo *fifo) return true; } -static int getch2_status=0; +static volatile int getch2_status=0; -void getch2_enable(void){ +static void do_enable_getch2(void) +{ #ifdef HAVE_TERMIOS -struct termios tio_new; - tcgetattr(0,&tio_orig); - tio_new=tio_orig; + struct termios tio_new; + tcgetattr(0,&tio_new); tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ tio_new.c_cc[VMIN] = 0; tio_new.c_cc[VTIME] = 0; tcsetattr(0,TCSANOW,&tio_new); #endif +} + +static void continue_sighandler(int signum) +{ + if (getch2_status) + do_enable_getch2(); +} + +void getch2_enable(void){ +#ifdef HAVE_TERMIOS + tcgetattr(0,&tio_orig); + do_enable_getch2(); +#endif getch2_status=1; + signal(SIGCONT,continue_sighandler); } void getch2_disable(void){ if(!getch2_status) return; // already disabled / never enabled + getch2_status=0; #ifdef HAVE_TERMIOS tcsetattr(0,TCSANOW,&tio_orig); #endif - getch2_status=0; } #ifdef CONFIG_ICONV diff --git a/osdep/io.c b/osdep/io.c index e3e750e30b..5531e3ce7c 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -92,13 +92,10 @@ int mp_stat(const char *path, struct stat *buf) return res; } -int mp_fprintf(FILE *stream, const char *format, ...) +static int mp_vfprintf(FILE *stream, const char *format, va_list args) { - va_list args; int done = 0; - va_start(args, format); - if (stream == stdout || stream == stderr) { HANDLE *wstream = GetStdHandle(stream == stdout ? @@ -146,9 +143,27 @@ int mp_fprintf(FILE *stream, const char *format, ...) else done = vfprintf(stream, format, args); + return done; +} + +int mp_fprintf(FILE *stream, const char *format, ...) +{ + int res; + va_list args; + va_start(args, format); + res = mp_vfprintf(stream, format, args); va_end(args); + return res; +} - return done; +int mp_printf(const char *format, ...) +{ + int res; + va_list args; + va_start(args, format); + res = mp_vfprintf(stdout, format, args); + va_end(args); + return res; } int mp_open(const char *filename, int oflag, ...) diff --git a/osdep/io.h b/osdep/io.h index 462a84917b..4383d61143 100644 --- a/osdep/io.h +++ b/osdep/io.h @@ -46,6 +46,7 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s); void mp_get_converted_argv(int *argc, char ***argv); int mp_stat(const char *path, struct stat *buf); +int mp_printf(const char *format, ...); int mp_fprintf(FILE *stream, const char *format, ...); int mp_open(const char *filename, int oflag, ...); int mp_creat(const char *filename, int mode); @@ -58,6 +59,7 @@ int mp_mkdir(const char *path, int mode); // NOTE: Stat is not overridden with mp_stat, because MinGW-w64 defines it as // macro. +#define printf(...) mp_printf(__VA_ARGS__) #define fprintf(...) mp_fprintf(__VA_ARGS__) #define open(...) mp_open(__VA_ARGS__) #define creat(...) mp_creat(__VA_ARGS__) |