From f698b93aa8d21ef99e51baeb86fbb775d706423b Mon Sep 17 00:00:00 2001 From: ars-ka0s <26339355+ars-ka0s@users.noreply.github.com> Date: Wed, 18 Jan 2023 00:09:45 -0600 Subject: [PATCH] Add check to ensure -O is used with stdout --- src/audio.c | 5 +++++ src/audio_win.c | 5 +++++ src/textcolor.c | 5 ++++- src/textcolor.h | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/audio.c b/src/audio.c index bfeb021..1884d5c 100644 --- a/src/audio.c +++ b/src/audio.c @@ -458,6 +458,11 @@ int audio_open (struct audio_s *pa) */ if (strcasecmp(pa->adev[a].adevice_out, "stdout") == 0 || strcmp(pa->adev[a].adevice_out, "-") == 0) { adev[a].g_audio_out_type = AUDIO_OUT_TYPE_STDOUT; + if (!dw_printf_redirected()) { + text_color_set (DW_COLOR_ERROR); + dw_printf ("stdout must only be used with the -O option\n"); + return (-1); + } } else { adev[a].g_audio_out_type = AUDIO_OUT_TYPE_SOUNDCARD; } diff --git a/src/audio_win.c b/src/audio_win.c index 805ded1..22346e2 100644 --- a/src/audio_win.c +++ b/src/audio_win.c @@ -354,6 +354,11 @@ int audio_open (struct audio_s *pa) */ if (strcasecmp(pa->adev[a].adevice_out, "stdout") == 0 || strcmp(pa->adev[a].adevice_out, "-") == 0) { A->g_audio_out_type = AUDIO_OUT_TYPE_STDOUT; + if (!dw_printf_redirected()) { + text_color_set (DW_COLOR_ERROR); + dw_printf ("stdout must only be used with the -O option\n"); + return (-1); + } /* Change - to stdout for readability. */ strlcpy (pa->adev[a].adevice_out, "stdout", sizeof(pa->adev[a].adevice_out)); } else { diff --git a/src/textcolor.c b/src/textcolor.c index 06a3b3e..b05c21d 100644 --- a/src/textcolor.c +++ b/src/textcolor.c @@ -388,7 +388,10 @@ int dw_printf (const char *fmt, ...) return (len); } - +int dw_printf_redirected () +{ + return g_dw_printf_dest != stdout; +} #if TESTC main () diff --git a/src/textcolor.h b/src/textcolor.h index 93dfc6b..123430e 100644 --- a/src/textcolor.h +++ b/src/textcolor.h @@ -55,4 +55,6 @@ int dw_printf (const char *fmt, ...) __attribute__((format(printf,1,2))); /* gnu C lib. */ #endif +int dw_printf_redirected (); + #endif