Eric Andersen | a9c6bc4 | 2003-03-07 17:29:12 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003 Erik Andersen <andersen@codepoet.org> |
Eric Andersen | a9c6bc4 | 2003-03-07 17:29:12 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <getopt.h> |
| 10 | #include <errno.h> |
| 11 | #include <assert.h> |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 12 | #include <ctype.h> |
Eric Andersen | a9c6bc4 | 2003-03-07 17:29:12 +0000 | [diff] [blame] | 13 | |
| 14 | #include "busybox.h" |
| 15 | |
Eric Andersen | a3bb3e6 | 2003-06-26 09:05:32 +0000 | [diff] [blame] | 16 | extern long bb_xgetlarg(const char *arg, int base, long lower, long upper) |
Eric Andersen | a9c6bc4 | 2003-03-07 17:29:12 +0000 | [diff] [blame] | 17 | { |
| 18 | long result; |
| 19 | char *endptr; |
| 20 | int errno_save = errno; |
| 21 | |
| 22 | assert(arg!=NULL); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 23 | |
| 24 | /* Don't allow leading whitespace. */ |
| 25 | if ((isspace)(*arg)) { /* Use an actual funciton call for minimal size. */ |
| 26 | bb_show_usage(); |
| 27 | } |
| 28 | |
Eric Andersen | a9c6bc4 | 2003-03-07 17:29:12 +0000 | [diff] [blame] | 29 | errno = 0; |
| 30 | result = strtol(arg, &endptr, base); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 31 | if (errno != 0 || *endptr!='\0' || endptr==arg || result < lower || result > upper) |
| 32 | bb_show_usage(); |
Eric Andersen | a9c6bc4 | 2003-03-07 17:29:12 +0000 | [diff] [blame] | 33 | errno = errno_save; |
| 34 | return result; |
| 35 | } |