Skip to content

Commit 94a0548

Browse files
committed
Add check to ensure -O is used with stdout
1 parent 953e8a2 commit 94a0548

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Diff for: src/audio.c

+5
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ int audio_open (struct audio_s *pa)
458458
*/
459459
if (strcasecmp(pa->adev[a].adevice_out, "stdout") == 0 || strcmp(pa->adev[a].adevice_out, "-") == 0) {
460460
adev[a].g_audio_out_type = AUDIO_OUT_TYPE_STDOUT;
461+
if (!dw_printf_redirected()) {
462+
text_color_set (DW_COLOR_ERROR);
463+
dw_printf ("stdout must only be used with the -O option\n");
464+
return (-1);
465+
}
461466
} else {
462467
adev[a].g_audio_out_type = AUDIO_OUT_TYPE_SOUNDCARD;
463468
}

Diff for: src/audio_win.c

+5
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ int audio_open (struct audio_s *pa)
354354
*/
355355
if (strcasecmp(pa->adev[a].adevice_out, "stdout") == 0 || strcmp(pa->adev[a].adevice_out, "-") == 0) {
356356
A->g_audio_out_type = AUDIO_OUT_TYPE_STDOUT;
357+
if (!dw_printf_redirected()) {
358+
text_color_set (DW_COLOR_ERROR);
359+
dw_printf ("stdout must only be used with the -O option\n");
360+
return (-1);
361+
}
357362
/* Change - to stdout for readability. */
358363
strlcpy (pa->adev[a].adevice_out, "stdout", sizeof(pa->adev[a].adevice_out));
359364
} else {

Diff for: src/textcolor.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,10 @@ int dw_printf (const char *fmt, ...)
388388
return (len);
389389
}
390390

391-
391+
int dw_printf_redirected ()
392+
{
393+
return g_dw_printf_dest != stdout;
394+
}
392395

393396
#if TESTC
394397
main ()

Diff for: src/textcolor.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ int dw_printf (const char *fmt, ...)
5555
__attribute__((format(printf,1,2))); /* gnu C lib. */
5656
#endif
5757

58+
int dw_printf_redirected ();
59+
5860
#endif

0 commit comments

Comments
 (0)