summaryrefslogtreecommitdiff
path: root/popt
diff options
context:
space:
mode:
Diffstat (limited to 'popt')
-rw-r--r--popt/Makefile2
-rw-r--r--popt/popt.c21
-rw-r--r--popt/popt.h2
3 files changed, 24 insertions, 1 deletions
diff --git a/popt/Makefile b/popt/Makefile
index 4a6998da1..b76b25e1d 100644
--- a/popt/Makefile
+++ b/popt/Makefile
@@ -1,6 +1,6 @@
LIBOBJECTS = popt.o
-DEFCFLAGS=-O2
+DEFCFLAGS=-O2 -Wall
SOURCES =$(subst .o,.c,$(LIBOBJECTS))
LIBPOPT = libpopt.a
diff --git a/popt/popt.c b/popt/popt.c
index d4dee0297..57b0041b5 100644
--- a/popt/popt.c
+++ b/popt/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);
diff --git a/popt/popt.h b/popt/popt.h
index 1b208d455..0072e2544 100644
--- a/popt/popt.h
+++ b/popt/popt.h
@@ -13,6 +13,8 @@
#define POPT_ERROR_OPTSTOODEEP -13
#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
+#define POPT_ERROR_BADNUMBER -17
+#define POPT_ERROR_OVERFLOW -18
#define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */