21606c40114d9b5c048e7063bde5b57767d8169e
[mmh] / sbr / m_atoi.c
1 /*
2  * m_atoi.c -- Parse a string representation of a message number, and
3  *          -- return the numeric value of the message.  If the string
4  *          -- contains any non-digit characters, then return 0.
5  *
6  * This code is Copyright (c) 2002, by the authors of nmh.  See the
7  * COPYRIGHT file in the root directory of the nmh distribution for
8  * complete copyright information.
9  */
10
11 #include <h/mh.h>
12
13
14 int
15 m_atoi (char *str)
16 {
17         int i;
18         unsigned char *cp;
19
20         for (i = 0, cp = str; *cp; cp++) {
21 #ifdef LOCALE
22                 if (!isdigit(*cp))
23 #else
24                 if (*cp < '0' || *cp > '9')
25 #endif
26                         return 0;
27
28                 i *= 10;
29                 i += (*cp - '0');
30         }
31
32         return i;
33 }