Module Name: src Committed By: christos Date: Wed May 27 17:55:23 UTC 2015
Modified Files: src/sbin/raidctl: raidctl.c Log Message: use strtou To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/sbin/raidctl/raidctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/raidctl/raidctl.c diff -u src/sbin/raidctl/raidctl.c:1.58 src/sbin/raidctl/raidctl.c:1.59 --- src/sbin/raidctl/raidctl.c:1.58 Wed May 27 11:31:15 2015 +++ src/sbin/raidctl/raidctl.c Wed May 27 13:55:23 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: raidctl.c,v 1.58 2015/05/27 15:31:15 manu Exp $ */ +/* $NetBSD: raidctl.c,v 1.59 2015/05/27 17:55:23 christos Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: raidctl.c,v 1.58 2015/05/27 15:31:15 manu Exp $"); +__RCSID("$NetBSD: raidctl.c,v 1.59 2015/05/27 17:55:23 christos Exp $"); #endif @@ -55,6 +55,7 @@ __RCSID("$NetBSD: raidctl.c,v 1.58 2015/ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <inttypes.h> #include <unistd.h> #include <util.h> @@ -85,7 +86,7 @@ static void get_bar(char *, double, int static void get_time_string(char *, int); static void rf_output_pmstat(int, int); static void rf_pm_configure(int, int, char *, int[]); -static unsigned int _strtoud(char *); +static unsigned int xstrtouint(const char *); int verbose; @@ -184,7 +185,7 @@ main(int argc,char *argv[]) break; case 'I': action = RAIDFRAME_INIT_LABELS; - serial_number = _strtoud(optarg); + serial_number = xstrtouint(optarg); num_options++; break; case 'm': @@ -200,7 +201,7 @@ main(int argc,char *argv[]) i = 0; while (i < 3 && optind < argc && isdigit((int)argv[optind][0])) - parityparams[i++] = _strtoud(argv[optind++]); + parityparams[i++] = xstrtouint(argv[optind++]); while (i < 3) parityparams[i++] = 0; break; @@ -1161,24 +1162,11 @@ usage(void) } static unsigned int -_strtoud(char *str) +xstrtouint(const char *str) { - long num; - char *ep; - - errno = 0; - num = strtol(str, &ep, 10); - if (str[0] == '\0' || *ep != '\0') - errx(1, "Not a number: %s", str); - - if (errno) - err(1, "Inavlid number %s", str); - - if (num < 0) - errx(1, "Negative number: %s", str); - - if (num > INT_MAX) - errx(1, "Number too large: %s", str); - - return (unsigned int)num; + int e; + unsigned int num = (unsigned int)strtou(str, NULL, 10, 0, INT_MAX, &e); + if (e) + errc(EXIT_FAILURE, e, "Bad number `%s'", str); + return num; }