]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Replace the macro STRINGINT with a function
authorRoy Marples <roy@marples.name>
Thu, 15 Nov 2007 17:57:10 +0000 (17:57 +0000)
committerRoy Marples <roy@marples.name>
Thu, 15 Nov 2007 17:57:10 +0000 (17:57 +0000)
dhcpcd.c

index bfd199947e0883043d427cc53cc7bd82b34b5579..fdd65ca9fae233d703f5aacea636784e8140b9ae 100644 (file)
--- 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);