From 706e4d6518e252ff9edac090142eb6e6a1f6a7df Mon Sep 17 00:00:00 2001 From: James Laird Date: Wed, 19 Jun 2013 13:56:11 +1000 Subject: [PATCH] ao, shairport: fix option parsing - don't push unrecognised args to the audio driver - get ao to parse from first argument - ao checks for unrecognised options --- audio_ao.c | 7 ++++++- shairport.c | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) 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) {