diff options
author | Omar Polo <op@omarpolo.com> | 2021-01-21 16:07:12 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-01-21 16:07:12 +0000 |
commit | a5a09e44b2ca3fa86ecf401f3907dff8c2012d98 (patch) | |
tree | f0428b2255beea3891c227e9bbe487948ab30c61 /gmid.c | |
parent | 5c342d059f884b73823e5a466902a3826b17e6c7 (diff) |
use strtonum
Diffstat (limited to 'gmid.c')
-rw-r--r-- | gmid.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -199,16 +199,13 @@ yyerror(const char *msg) int parse_portno(const char *p) { - char *ep; - long lval; - - errno = 0; - lval = strtol(p, &ep, 10); - if (p[0] == '\0' || *ep != '\0') - fatal("not a number: %s", p); - if (lval < 0 || lval > UINT16_MAX) - fatal("port number out of range for domain %s: %ld", p, lval); - return lval; + char *errstr; + int n; + + n = strtonum(p, 0, UINT16_MAX, &errstr); + if (errstr != NULL) + errx(1, "port number is %s: %s", errstr, p); + return n; } void |