Get a good start on cleaning up powermgmt.c
[kugel-rb.git] / firmware / common / atoi.c
blobeb43b613367f48caaf55742300eb9b694a38f98c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Gary Czvitkovicz
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <stdlib.h>
21 #include "ctype.h"
23 int atoi (const char *str)
25 int value = 0;
26 int sign = 1;
28 while (isspace(*str))
30 str++;
33 if ('-' == *str)
35 sign = -1;
36 str++;
38 else if ('+' == *str)
40 str++;
43 while ('0' == *str)
45 str++;
48 while (isdigit(*str))
50 value = (value * 10) + (*str - '0');
51 str++;
54 return value * sign;