1*35102Sbostic /* 2*35102Sbostic * Copyright (c) 1988 Regents of the University of California. 3*35102Sbostic * All rights reserved. 4*35102Sbostic * 5*35102Sbostic * Redistribution and use in source and binary forms are permitted 6*35102Sbostic * provided that the above copyright notice and this paragraph are 7*35102Sbostic * duplicated in all such forms and that any documentation, 8*35102Sbostic * advertising materials, and other materials related to such 9*35102Sbostic * distribution and use acknowledge that the software was developed 10*35102Sbostic * by the University of California, Berkeley. The name of the 11*35102Sbostic * University may not be used to endorse or promote products derived 12*35102Sbostic * from this software without specific prior written permission. 13*35102Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*35102Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*35102Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*35102Sbostic */ 17*35102Sbostic 1826542Sdonn #if defined(LIBC_SCCS) && !defined(lint) 19*35102Sbostic static char sccsid[] = "@(#)atoi.c 5.3 (Berkeley) 07/19/88"; 20*35102Sbostic #endif /* LIBC_SCCS and not lint */ 2122080Smckusick 22*35102Sbostic #include <ctype.h> 23*35102Sbostic 24*35102Sbostic atoi(ascii) 25*35102Sbostic register char *ascii; 261954Swnj { 27*35102Sbostic register int val; 28*35102Sbostic int negative = 0; 291954Swnj 30*35102Sbostic for (; isascii(*ascii) && isspace(*ascii); ++ascii); 31*35102Sbostic if (*ascii == '+') 32*35102Sbostic ++ascii; 33*35102Sbostic else if (*ascii == '-') { 34*35102Sbostic ++ascii; 35*35102Sbostic negative = 1; 361954Swnj } 37*35102Sbostic for (val = 0; isascii(*ascii) && isdigit(*ascii); ++ascii) 38*35102Sbostic val = val * 10 + *ascii - '0'; 39*35102Sbostic return(negative ? -val : val); 401954Swnj } 41