Upgrade netcat a lot. Make -e able to take the rest of the command line as
[oweals/busybox.git] / libbb / xgetlarg.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2003-2004 Erik Andersen <andersen@codepoet.org>
4  *
5  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <getopt.h>
11 #include <errno.h>
12 #include <assert.h>
13 #include <ctype.h>
14
15 #include "libbb.h"
16
17 long bb_xgetlarg(const char *arg, int base, long lower, long upper)
18 {
19         long result;
20         char *endptr;
21         int errno_save = errno;
22
23         assert(arg!=NULL);
24
25         /* Don't allow leading whitespace.
26          * Wrap isspace in () to make sure we call the
27          * function rather than the macro. */
28         if ((isspace)(*arg)) {
29                 bb_show_usage();
30         }
31
32         errno = 0;
33         result = strtol(arg, &endptr, base);
34         if (errno != 0 || *endptr!='\0' || endptr==arg || result < lower || result > upper)
35                 bb_show_usage();
36         errno = errno_save;
37         return result;
38 }