diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1998-06-07 21:02:38 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1998-06-07 21:02:38 +0000 |
commit | 661782c919727ee927e35dc059d0dd27d091d326 (patch) | |
tree | 35e63772f28e227a30b2ee3c98c30a182b097345 /options.c | |
parent | 7e496ae9a594a8b5a7f430948143f3ee35c85631 (diff) | |
download | fetchmail-661782c919727ee927e35dc059d0dd27d091d326.tar.gz fetchmail-661782c919727ee927e35dc059d0dd27d091d326.tar.bz2 fetchmail-661782c919727ee927e35dc059d0dd27d091d326.zip |
More from Gunter.
svn path=/trunk/; revision=1925
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -13,6 +13,8 @@ #if defined(STDC_HEADERS) #include <stdlib.h> #include <limits.h> +#else +#include <ctype.h> #endif #include "getopt.h" @@ -159,7 +161,39 @@ static int xatoi(char *s, int *errflagptr) return (int) value; /* shut up, I know what I'm doing */ #else - return atoi(s); + int i; + char *dp; +# if defined (STDC_HEADERS) + size_t len; +# else + int len; +# endif + + /* We do only base 10 conversions here (atoi)! */ + + len = strlen(s); + /* check for leading white spaces */ + for (i = 0; (i < len) && isspace(s[i]); i++) + ; + + dp = &s[i]; + + /* check for +/- */ + if (i < len && (s[i] == '+' || s[i] == '-')) i++; + + /* skip over digits */ + for ( /* no init */ ; (i < len) && isdigit(s[i]); i++) + ; + + /* check for trailing garbage */ + if (i != len) { + (void) fprintf(stderr, "String '%s' is not a valid number string.\n", s); + (*errflagptr)++; + return 0; + } + + /* atoi should be safe by now, except for number range over/underflow */ + return atoi(dp); #endif } |