Mercurial > hg > dhcpcd
changeset 241:5ab6cece6c6b draft
Replace the macro STRINGINT with a function
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Thu, 15 Nov 2007 17:57:10 +0000 |
| parents | fcfe7e7b5344 |
| children | 43bd36a18297 |
| files | dhcpcd.c |
| diffstat | 1 files changed, 19 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/dhcpcd.c Thu Nov 15 12:04:28 2007 +0000 +++ b/dhcpcd.c Thu Nov 15 17:57:10 2007 +0000 @@ -95,21 +95,6 @@ {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 @@ #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 @@ 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 @@ } 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);
