[pacman-dev] [PATCH] check for -1 return value from getopt_long
Andrew Gregory
andrew.gregory.8 at gmail.com
Thu Oct 24 19:52:59 EDT 2013
getopt_long returns -1 when it has finished parsing all args. A return
value of 0 indicates that a flag was set directly by getopt_long and
parsing should continue.
Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
src/pacman/pacman.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index f485692..5ae15ce 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -878,10 +878,8 @@ static int parseargs(int argc, char *argv[])
};
/* parse operation */
- while((opt = getopt_long(argc, argv, optstring, opts, &option_index))) {
- if(opt < 0) {
- break;
- } else if(opt == 0) {
+ while((opt = getopt_long(argc, argv, optstring, opts, &option_index)) != -1) {
+ if(opt == 0) {
continue;
} else if(opt == '?') {
/* unknown option, getopt printed an error */
@@ -905,10 +903,8 @@ static int parseargs(int argc, char *argv[])
/* parse all other options */
optind = 1;
- while((opt = getopt_long(argc, argv, optstring, opts, &option_index))) {
- if(opt < 0) {
- break;
- } else if(opt == 0) {
+ while((opt = getopt_long(argc, argv, optstring, opts, &option_index)) != -1) {
+ if(opt == 0) {
continue;
} else if(opt == '?') {
/* this should have failed during first pass already */
--
1.8.4.1
More information about the pacman-dev
mailing list