Add check to ensure -O is used with stdout

This commit is contained in:
ars-ka0s 2023-01-18 00:09:45 -06:00
parent 41b32703b1
commit f698b93aa8
4 changed files with 16 additions and 1 deletions

View File

@ -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) { 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; 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 { } else {
adev[a].g_audio_out_type = AUDIO_OUT_TYPE_SOUNDCARD; adev[a].g_audio_out_type = AUDIO_OUT_TYPE_SOUNDCARD;
} }

View File

@ -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) { 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; 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. */ /* Change - to stdout for readability. */
strlcpy (pa->adev[a].adevice_out, "stdout", sizeof(pa->adev[a].adevice_out)); strlcpy (pa->adev[a].adevice_out, "stdout", sizeof(pa->adev[a].adevice_out));
} else { } else {

View File

@ -388,7 +388,10 @@ int dw_printf (const char *fmt, ...)
return (len); return (len);
} }
int dw_printf_redirected ()
{
return g_dw_printf_dest != stdout;
}
#if TESTC #if TESTC
main () main ()

View File

@ -55,4 +55,6 @@ int dw_printf (const char *fmt, ...)
__attribute__((format(printf,1,2))); /* gnu C lib. */ __attribute__((format(printf,1,2))); /* gnu C lib. */
#endif #endif
int dw_printf_redirected ();
#endif #endif