diff options
author | Erik Troan <ewt@src.gnome.org> | 1997-11-02 16:12:56 +0000 |
---|---|---|
committer | Erik Troan <ewt@src.gnome.org> | 1997-11-02 16:12:56 +0000 |
commit | fa601d8fb2294c43aaa03365b23a03e59fba252e (patch) | |
tree | 98510332aa0122f23fa6389f48347497a066f865 /support/popt.c | |
parent | e23459d6b908207705df046dd0067d1976be3532 (diff) | |
download | shared-mime-info-fa601d8fb2294c43aaa03365b23a03e59fba252e.tar.gz |
implmented POPT_ARG_INT and POPT_ARG_LONG
svn path=/trunk/; revision=37
Diffstat (limited to 'support/popt.c')
-rw-r--r-- | support/popt.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/support/popt.c b/support/popt.c index d4dee029..57b0041b 100644 --- a/support/popt.c +++ b/support/popt.c @@ -1,6 +1,7 @@ #include <errno.h> #include <ctype.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -75,6 +76,8 @@ int poptGetNextOpt(poptContext con) { char * optString, * chptr, * localOptString; char * longArg = NULL; char * origOptString; + long aLong; + char * end; struct poptOption * opt = NULL; int done = 0; int i; @@ -214,6 +217,24 @@ int poptGetNextOpt(poptContext con) { case POPT_ARG_STRING: *((char **) opt->arg) = con->os->nextArg; break; + + case POPT_ARG_INT: + case POPT_ARG_LONG: + aLong = strtol(con->os->nextArg, &end, 0); + if (*end) + return POPT_ERROR_BADNUMBER; + + if (aLong == LONG_MIN || aLong == LONG_MAX) + return POPT_ERROR_OVERFLOW; + if (opt->argInfo == POPT_ARG_LONG) { + *((long *) opt->arg) = aLong; + } else { + if (aLong > INT_MAX || aLong < INT_MIN) + return POPT_ERROR_OVERFLOW; + *((int *) opt->arg) =aLong; + } + break; + default: printf("option type not implemented in popt\n"); exit(1); |