diff --git a/audio_ao.c b/audio_ao.c index c9ccd309..9f133f02 100644 --- a/audio_ao.c +++ b/audio_ao.c @@ -47,7 +47,9 @@ static int init(int argc, char **argv) { int driver = ao_default_driver_id(); ao_option *ao_opts = NULL; - optind = 0; + optind = 1; // optind=0 is equivalent to optind=1 plus special behaviour + argv--; // so we shift the arguments to satisfy getopt() + argc++; // some platforms apparently require optreset = 1; - which? int opt; char *mid; @@ -80,6 +82,9 @@ static int init(int argc, char **argv) { } } + if (optind < argc) + die("Invalid audio argument: %s", argv[optind]); + ao_sample_format fmt; memset(&fmt, 0, sizeof(fmt)); diff --git a/shairport.c b/shairport.c index 6531b0ca..59d9c89c 100644 --- a/shairport.c +++ b/shairport.c @@ -88,6 +88,9 @@ void usage(char *progname) { } int parse_options(int argc, char **argv) { + // prevent unrecognised arguments from being shunted to the audio driver + setenv("POSIXLY_CORRECT", "", 1); + int opt; while ((opt = getopt(argc, argv, "+hdvp:a:o:b:B:E:")) > 0) { switch (opt) {