summaryrefslogtreecommitdiffstats
path: root/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-11-15 17:57:10 +0000
committerRoy Marples <roy@marples.name>2007-11-15 17:57:10 +0000
commit05bea32986dfead298f0030e5361871948c78da6 (patch)
tree4c446e96fa7a3a36f04d0729a9521a817c78ce8c /dhcpcd.c
parentaedfde99fb2a466fa1dc826355b90f69e850b63f (diff)
downloaddhcpcd-05bea32986dfead298f0030e5361871948c78da6.tar.xz
Replace the macro STRINGINT with a function
Diffstat (limited to 'dhcpcd.c')
-rw-r--r--dhcpcd.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/dhcpcd.c b/dhcpcd.c
index bfd19994..fdd65ca9 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -95,21 +95,6 @@ static const struct option longopts[] = {
{NULL, 0, NULL, 0}
};
-
-#define STRINGINT(_string, _int) { \
- char *_tmp; \
- long _number = strtol (_string, &_tmp, 0); \
- errno = 0; \
- if ((errno != 0 && _number == 0) || _string == _tmp || \
- (errno == ERANGE && (_number == LONG_MAX || _number == LONG_MIN))) \
- { \
- logger (LOG_ERR, "`%s' out of range", _string);; \
- exit (EXIT_FAILURE); \
- } \
- else \
- _int = (int) _number; \
-}
-
#ifdef THERE_IS_NO_FORK
char dhcpcd[PATH_MAX];
char **dhcpcd_argv = NULL;
@@ -119,6 +104,22 @@ char *dhcpcd_skiproutes = NULL;
#define EXTRA_OPTS "fg:"
#endif
+static int atoint (const char *s)
+{
+ char *t;
+ long n = strtol (s, &t, 0);
+
+ errno = 0;
+ if ((errno != 0 && n == 0) || s == t ||
+ (errno == ERANGE && (n == LONG_MAX || n == LONG_MIN)))
+ {
+ logger (LOG_ERR, "`%s' out of range", s);
+ exit (EXIT_FAILURE);
+ }
+
+ return n;
+}
+
static pid_t read_pid (const char *pidfile)
{
FILE *fp;
@@ -247,14 +248,14 @@ int main(int argc, char **argv)
sig = SIGHUP;
break;
case 'l':
- STRINGINT (optarg, options->leasetime);
+ options->leasetime = atoint (optarg);
if (options->leasetime <= 0) {
logger (LOG_ERR, "leasetime must be a positive value");
exit (EXIT_FAILURE);
}
break;
case 'm':
- STRINGINT (optarg, options->metric);
+ options->metric = atoint (optarg);
break;
case 'n':
sig = SIGALRM;
@@ -294,7 +295,7 @@ int main(int argc, char **argv)
}
break;
case 't':
- STRINGINT (optarg, options->timeout);
+ options->timeout = atoint (optarg);
if (options->timeout < 0) {
logger (LOG_ERR, "timeout must be a positive value");
exit (EXIT_FAILURE);