Module Name: src Committed By: isaki Date: Sun Aug 10 07:40:50 UTC 2014
Modified Files: src/sys/arch/hp300/stand/common: devopen.c samachdep.h src/sys/arch/hp300/stand/inst: inst.c src/sys/arch/i386/stand/lib: bootmenu.c bootmenu.h src/sys/arch/next68k/stand/boot: devopen.c src/sys/arch/prep/stand/boot: devopen.c src/sys/arch/rs6000/stand/boot: devopen.c src/sys/arch/x68k/stand/boot: switch.c src/sys/arch/zaurus/stand/zboot: bootmenu.c bootmenu.h src/sys/lib/libsa: Makefile bootcfg.c stand.h Added Files: src/sys/lib/libsa: atoi.c Log Message: Unify all arch/*/stand's atoi() to MI libsa. lib/libsa/atoi.c was separated from lib/libsa/bootcfg.c. PR/49084 To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/arch/hp300/stand/common/devopen.c cvs rdiff -u -r1.17 -r1.18 src/sys/arch/hp300/stand/common/samachdep.h cvs rdiff -u -r1.19 -r1.20 src/sys/arch/hp300/stand/inst/inst.c cvs rdiff -u -r1.13 -r1.14 src/sys/arch/i386/stand/lib/bootmenu.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/i386/stand/lib/bootmenu.h cvs rdiff -u -r1.5 -r1.6 src/sys/arch/next68k/stand/boot/devopen.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/prep/stand/boot/devopen.c cvs rdiff -u -r1.1 -r1.2 src/sys/arch/rs6000/stand/boot/devopen.c cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x68k/stand/boot/switch.c cvs rdiff -u -r1.3 -r1.4 src/sys/arch/zaurus/stand/zboot/bootmenu.c cvs rdiff -u -r1.2 -r1.3 src/sys/arch/zaurus/stand/zboot/bootmenu.h cvs rdiff -u -r1.83 -r1.84 src/sys/lib/libsa/Makefile cvs rdiff -u -r0 -r1.1 src/sys/lib/libsa/atoi.c cvs rdiff -u -r1.1 -r1.2 src/sys/lib/libsa/bootcfg.c cvs rdiff -u -r1.78 -r1.79 src/sys/lib/libsa/stand.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/hp300/stand/common/devopen.c diff -u src/sys/arch/hp300/stand/common/devopen.c:1.10 src/sys/arch/hp300/stand/common/devopen.c:1.11 --- src/sys/arch/hp300/stand/common/devopen.c:1.10 Mon Apr 28 20:23:19 2008 +++ src/sys/arch/hp300/stand/common/devopen.c Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: devopen.c,v 1.10 2008/04/28 20:23:19 martin Exp $ */ +/* $NetBSD: devopen.c,v 1.11 2014/08/10 07:40:49 isaki Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -73,16 +73,6 @@ static void usage(void); static int devlookup(const char * ,int); static int devparse(const char *, int *, int*, int*, int*, int*, char **); -int -atoi(char *cp) -{ - int val = 0; - - while (isdigit((unsigned char)*cp)) - val = val * 10 + (*cp++ - '0'); - return val; -} - void usage(void) { Index: src/sys/arch/hp300/stand/common/samachdep.h diff -u src/sys/arch/hp300/stand/common/samachdep.h:1.17 src/sys/arch/hp300/stand/common/samachdep.h:1.18 --- src/sys/arch/hp300/stand/common/samachdep.h:1.17 Sat Apr 19 06:04:58 2014 +++ src/sys/arch/hp300/stand/common/samachdep.h Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: samachdep.h,v 1.17 2014/04/19 06:04:58 tsutsui Exp $ */ +/* $NetBSD: samachdep.h,v 1.18 2014/08/10 07:40:49 isaki Exp $ */ /* * Copyright (c) 1982, 1990, 1993 @@ -74,7 +74,6 @@ int cnputc(int); /* devopen.c */ extern u_int opendev; -int atoi(char *); /* exec.c */ void exec_hp300(char *, u_long, int); Index: src/sys/arch/hp300/stand/inst/inst.c diff -u src/sys/arch/hp300/stand/inst/inst.c:1.19 src/sys/arch/hp300/stand/inst/inst.c:1.20 --- src/sys/arch/hp300/stand/inst/inst.c:1.19 Sat Jun 21 02:01:21 2014 +++ src/sys/arch/hp300/stand/inst/inst.c Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: inst.c,v 1.19 2014/06/21 02:01:21 tsutsui Exp $ */ +/* $NetBSD: inst.c,v 1.20 2014/08/10 07:40:49 isaki Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -760,18 +760,11 @@ resetsys(void) __asm("stop #0x2700"); } -/* - * XXX Should have a generic atoi for libkern/libsa. - */ int a2int(char *cp) { - int i = 0; - if (*cp == '\0') - return (-1); + return -1; - while (*cp != '\0') - i = i * 10 + *cp++ - '0'; - return (i); + return atoi(cp); } Index: src/sys/arch/i386/stand/lib/bootmenu.c diff -u src/sys/arch/i386/stand/lib/bootmenu.c:1.13 src/sys/arch/i386/stand/lib/bootmenu.c:1.14 --- src/sys/arch/i386/stand/lib/bootmenu.c:1.13 Sat Jun 28 09:16:18 2014 +++ src/sys/arch/i386/stand/lib/bootmenu.c Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: bootmenu.c,v 1.13 2014/06/28 09:16:18 rtr Exp $ */ +/* $NetBSD: bootmenu.c,v 1.14 2014/08/10 07:40:49 isaki Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -40,8 +40,6 @@ #include <libi386.h> #include <bootmenu.h> -#define isnum(c) ((c) >= '0' && (c) <= '9') - static void docommandchoice(int); extern struct x86_boot_params boot_params; @@ -51,22 +49,6 @@ extern const char bootprog_name[], bootp #define MENUFORMAT_NUMBER 1 #define MENUFORMAT_LETTER 2 -int -atoi(const char *in) -{ - char *c; - int ret; - - ret = 0; - c = (char *)in; - if (*c == '-') - c++; - for (; isnum(*c); c++) - ret = (ret * 10) + (*c - '0'); - - return (*in == '-') ? -ret : ret; -} - /* * XXX * if module_add, userconf_add are strictly mi they can be folded back @@ -105,14 +87,14 @@ getchoicefrominput(char *input, int def) choice = (*input) - 'A'; else if (*input >= 'a' && *input < bootcfg_info.nummenu + 'a') choice = (*input) - 'a'; - else if (isnum(*input)) { + else if (isdigit(*input)) { choice = atoi(input) - 1; if (choice < 0 || choice >= bootcfg_info.nummenu) choice = -1; } if (bootcfg_info.menuformat != MENUFORMAT_LETTER && - !isnum(*input) && !usedef) + !isdigit(*input) && !usedef) choice = -1; return choice; Index: src/sys/arch/i386/stand/lib/bootmenu.h diff -u src/sys/arch/i386/stand/lib/bootmenu.h:1.4 src/sys/arch/i386/stand/lib/bootmenu.h:1.5 --- src/sys/arch/i386/stand/lib/bootmenu.h:1.4 Sat Jun 28 09:16:18 2014 +++ src/sys/arch/i386/stand/lib/bootmenu.h Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: bootmenu.h,v 1.4 2014/06/28 09:16:18 rtr Exp $ */ +/* $NetBSD: bootmenu.h,v 1.5 2014/08/10 07:40:49 isaki Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -34,6 +34,5 @@ void parsebootconf(const char *); void doboottypemenu(void); void bootdefault(void); -int atoi(const char *); #endif /* !_BOOTMENU_H */ Index: src/sys/arch/next68k/stand/boot/devopen.c diff -u src/sys/arch/next68k/stand/boot/devopen.c:1.5 src/sys/arch/next68k/stand/boot/devopen.c:1.6 --- src/sys/arch/next68k/stand/boot/devopen.c:1.5 Sun Dec 11 12:18:29 2005 +++ src/sys/arch/next68k/stand/boot/devopen.c Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: devopen.c,v 1.5 2005/12/11 12:18:29 christos Exp $ */ +/* $NetBSD: devopen.c,v 1.6 2014/08/10 07:40:49 isaki Exp $ */ /* * Copyright (c) 1994 Rolf Grossmann * All rights reserved. @@ -32,21 +32,10 @@ #include <lib/libsa/stand.h> #include <lib/libkern/libkern.h> -int atoi(const char *); int devlookup(const char *, int); int devparse(const char *, int *, char *, char *, char *, char **); int -atoi(const char *cp) -{ - int val = 0; - - while(isdigit((unsigned char)*cp)) - val = val * 10 + (*cp++ - '0'); - return val; -} - -int devlookup(const char *d, int len) { struct devsw *dp = devsw; Index: src/sys/arch/prep/stand/boot/devopen.c diff -u src/sys/arch/prep/stand/boot/devopen.c:1.4 src/sys/arch/prep/stand/boot/devopen.c:1.5 --- src/sys/arch/prep/stand/boot/devopen.c:1.4 Sat May 19 14:40:13 2012 +++ src/sys/arch/prep/stand/boot/devopen.c Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: devopen.c,v 1.4 2012/05/19 14:40:13 kiyohara Exp $ */ +/* $NetBSD: devopen.c,v 1.5 2014/08/10 07:40:49 isaki Exp $ */ /*- * Copyright (c) 1993 John Brezak @@ -33,21 +33,10 @@ #define ispart(c) ((c) >= 'a' && (c) <= 'h') -int atoi(char *); int devlookup(char *); int devparse(const char *, int *, int *, int *, int *, int *, char **); int -atoi(char *cp) -{ - int val = 0; - - while (isdigit(*cp)) - val = val * 10 + (*cp++ - '0'); - return (val); -} - -int devlookup(char *d) { struct devsw *dp = devsw; Index: src/sys/arch/rs6000/stand/boot/devopen.c diff -u src/sys/arch/rs6000/stand/boot/devopen.c:1.1 src/sys/arch/rs6000/stand/boot/devopen.c:1.2 --- src/sys/arch/rs6000/stand/boot/devopen.c:1.1 Mon Dec 17 19:09:48 2007 +++ src/sys/arch/rs6000/stand/boot/devopen.c Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: devopen.c,v 1.1 2007/12/17 19:09:48 garbled Exp $ */ +/* $NetBSD: devopen.c,v 1.2 2014/08/10 07:40:49 isaki Exp $ */ /*- * Copyright (c) 1993 John Brezak @@ -33,21 +33,10 @@ #define ispart(c) ((c) >= 'a' && (c) <= 'h') -int atoi(char *); int devlookup(char *); int devparse(const char *, int *, int *, int *, int *, int *, char **); int -atoi(char *cp) -{ - int val = 0; - - while (isdigit(*cp)) - val = val * 10 + (*cp++ - '0'); - return (val); -} - -int devlookup(char *d) { struct devsw *dp = devsw; Index: src/sys/arch/x68k/stand/boot/switch.c diff -u src/sys/arch/x68k/stand/boot/switch.c:1.1 src/sys/arch/x68k/stand/boot/switch.c:1.2 --- src/sys/arch/x68k/stand/boot/switch.c:1.1 Tue Aug 5 13:49:04 2014 +++ src/sys/arch/x68k/stand/boot/switch.c Sun Aug 10 07:40:50 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: switch.c,v 1.1 2014/08/05 13:49:04 isaki Exp $ */ +/* $NetBSD: switch.c,v 1.2 2014/08/10 07:40:50 isaki Exp $ */ /* * Copyright (c) 2014 Tetsuya Isaki. All rights reserved. @@ -63,22 +63,6 @@ sram_write_disable(void) } static int -atoi(const char *in) -{ - char *c; - int ret; - - ret = 0; - c = (char *)in; - if (*c == '-') - c++; - for (; isdigit(*c); c++) - ret = (ret * 10) + (*c - '0'); - - return (*in == '-') ? -ret : ret; -} - -static int hextoi(const char *in) { char *c; Index: src/sys/arch/zaurus/stand/zboot/bootmenu.c diff -u src/sys/arch/zaurus/stand/zboot/bootmenu.c:1.3 src/sys/arch/zaurus/stand/zboot/bootmenu.c:1.4 --- src/sys/arch/zaurus/stand/zboot/bootmenu.c:1.3 Sat Jun 28 09:16:18 2014 +++ src/sys/arch/zaurus/stand/zboot/bootmenu.c Sun Aug 10 07:40:50 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: bootmenu.c,v 1.3 2014/06/28 09:16:18 rtr Exp $ */ +/* $NetBSD: bootmenu.c,v 1.4 2014/08/10 07:40:50 isaki Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -35,28 +35,10 @@ #include "bootmenu.h" #include "pathnames.h" -#define isnum(c) ((c) >= '0' && (c) <= '9') - #define MENUFORMAT_AUTO 0 #define MENUFORMAT_NUMBER 1 #define MENUFORMAT_LETTER 2 -int -atoi(const char *in) -{ - char *c; - int ret; - - ret = 0; - c = (char *)in; - if (*c == '-') - c++; - for (; isnum(*c); c++) - ret = (ret * 10) + (*c - '0'); - - return (*in == '-') ? -ret : ret; -} - void parsebootconf(const char *conf) { @@ -77,7 +59,7 @@ getchoicefrominput(char *input, int def) choice = (*input) - 'A'; else if (*input >= 'a' && *input < bootcfg_info.nummenu + 'a') choice = (*input) - 'a'; - else if (isnum(*input)) { + else if (isdigit(*input)) { choice = atoi(input) - 1; if (choice < 0 || choice >= bootcfg_info.nummenu) choice = -1; Index: src/sys/arch/zaurus/stand/zboot/bootmenu.h diff -u src/sys/arch/zaurus/stand/zboot/bootmenu.h:1.2 src/sys/arch/zaurus/stand/zboot/bootmenu.h:1.3 --- src/sys/arch/zaurus/stand/zboot/bootmenu.h:1.2 Sat Jun 28 09:16:18 2014 +++ src/sys/arch/zaurus/stand/zboot/bootmenu.h Sun Aug 10 07:40:50 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: bootmenu.h,v 1.2 2014/06/28 09:16:18 rtr Exp $ */ +/* $NetBSD: bootmenu.h,v 1.3 2014/08/10 07:40:50 isaki Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -33,6 +33,5 @@ void parsebootconf(const char *); void doboottypemenu(void); -int atoi(const char *); #endif /* !_BOOTMENU_H */ Index: src/sys/lib/libsa/Makefile diff -u src/sys/lib/libsa/Makefile:1.83 src/sys/lib/libsa/Makefile:1.84 --- src/sys/lib/libsa/Makefile:1.83 Sat Jun 28 09:16:18 2014 +++ src/sys/lib/libsa/Makefile Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.83 2014/06/28 09:16:18 rtr Exp $ +# $NetBSD: Makefile,v 1.84 2014/08/10 07:40:49 isaki Exp $ LIB= sa LIBISPRIVATE?= yes @@ -23,7 +23,7 @@ CPPFLAGS= -I${SADIR} ${SACPPFLAGS} ${SAM .PATH.c: ${SADIR} ${.PARSEDIR}/../../../common/lib/libc/string # stand routines -SRCS+= alloc.c errno.c exit.c files.c \ +SRCS+= alloc.c atoi.c errno.c exit.c files.c \ getfile.c gets.c globals.c \ panic.c printf.c qsort.c snprintf.c strerror.c \ subr_prf.c twiddle.c checkpasswd.c Index: src/sys/lib/libsa/bootcfg.c diff -u src/sys/lib/libsa/bootcfg.c:1.1 src/sys/lib/libsa/bootcfg.c:1.2 --- src/sys/lib/libsa/bootcfg.c:1.1 Sat Jun 28 09:16:18 2014 +++ src/sys/lib/libsa/bootcfg.c Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: bootcfg.c,v 1.1 2014/06/28 09:16:18 rtr Exp $ */ +/* $NetBSD: bootcfg.c,v 1.2 2014/08/10 07:40:49 isaki Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -33,10 +33,6 @@ #include <lib/libsa/bootcfg.h> #include <lib/libkern/libkern.h> -static int atoi(const char *); - -#define isnum(c) ((c) >= '0' && (c) <= '9') - #define MENUFORMAT_AUTO 0 #define MENUFORMAT_NUMBER 1 #define MENUFORMAT_LETTER 2 @@ -46,22 +42,6 @@ static int atoi(const char *); struct bootcfg_def bootcfg_info; -int -atoi(const char *in) -{ - char *c; - int ret; - - ret = 0; - c = (char *)in; - if (*c == '-') - c++; - for (; isnum(*c); c++) - ret = (ret * 10) + (*c - '0'); - - return (*in == '-') ? -ret : ret; -} - void bootcfg_do_noop(const char *cmd, char *arg) { @@ -231,7 +211,7 @@ perform_bootcfg(const char *conf, bootcf if (cbanner < BOOTCFG_MAXBANNER) bootcfg_info.banner[cbanner++] = value; } else if (!strncmp(key, "timeout", 7)) { - if (!isnum(*value)) + if (!isdigit(*value)) bootcfg_info.timeout = -1; else bootcfg_info.timeout = atoi(value); Index: src/sys/lib/libsa/stand.h diff -u src/sys/lib/libsa/stand.h:1.78 src/sys/lib/libsa/stand.h:1.79 --- src/sys/lib/libsa/stand.h:1.78 Wed Mar 26 18:02:24 2014 +++ src/sys/lib/libsa/stand.h Sun Aug 10 07:40:49 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: stand.h,v 1.78 2014/03/26 18:02:24 christos Exp $ */ +/* $NetBSD: stand.h,v 1.79 2014/08/10 07:40:49 isaki Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -319,4 +319,6 @@ int fnmatch(const char *, const char *); void bcopy(const void *, void *, size_t); void bzero(void *, size_t); +int atoi(const char *); + #endif /* _LIBSA_STAND_H_ */ Added files: Index: src/sys/lib/libsa/atoi.c diff -u /dev/null src/sys/lib/libsa/atoi.c:1.1 --- /dev/null Sun Aug 10 07:40:50 2014 +++ src/sys/lib/libsa/atoi.c Sun Aug 10 07:40:49 2014 @@ -0,0 +1,49 @@ +/* $NetBSD: atoi.c,v 1.1 2014/08/10 07:40:49 isaki Exp $ */ + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/reboot.h> + +#include <lib/libsa/stand.h> +#include <lib/libkern/libkern.h> + +int +atoi(const char *in) +{ + char *c; + int ret; + + ret = 0; + c = (char *)in; + if (*c == '-') + c++; + for (; isdigit(*c); c++) + ret = (ret * 10) + (*c - '0'); + + return (*in == '-') ? -ret : ret; +}