From 7ea35b8afaaf6d59877e477e1ab7171f96cd698c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Jul 2008 19:39:40 +0000 Subject: [PATCH] (libT) avoid collisions between short & long getopts --- libtransmission/tr-getopt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libtransmission/tr-getopt.c b/libtransmission/tr-getopt.c index 286547d89..2077134f4 100644 --- a/libtransmission/tr-getopt.c +++ b/libtransmission/tr-getopt.c @@ -116,8 +116,9 @@ findOption( const tr_option * opts, size_t len; const tr_option * o; - for( o=opts; o->val; ++o ) - { + /* try all the longopts first to avoid collisions between + long options, and short options with args appended to them */ + for( o=opts; o->val; ++o ) { if( o->longName && (str[0]=='-') && (str[1]=='-') ) { if( !strcmp( o->longName, str+2 ) ) { if( nested ) *nested = NULL; @@ -129,7 +130,11 @@ findOption( const tr_option * opts, return o; } } - + } + + /* look for a matching shortopt */ + for( o=opts; o->val; ++o ) + { if( o->shortName && (str[0]=='-') ) { if( !strcmp( o->shortName, str+1 ) ) { if( nested ) *nested = NULL;