]> diplodocus.org Git - nmh/blob - sbr/m_atoi.c
Just reworded the bit about '%s' being safe not to quote (it's only safe not to
[nmh] / sbr / m_atoi.c
1
2 /*
3 * m_atoi.c -- Parse a string representation of a message number, and
4 * -- return the numeric value of the message. If the string
5 * -- contains any non-digit characters, then return 0.
6 *
7 * $Id$
8 */
9
10 #include <h/mh.h>
11
12
13 int
14 m_atoi (char *str)
15 {
16 int i;
17 char *cp;
18
19 for (i = 0, cp = str; *cp; cp++) {
20 #ifdef LOCALE
21 if (!isdigit(*cp))
22 #else
23 if (*cp < '0' || *cp > '9')
24 #endif
25 return 0;
26
27 i *= 10;
28 i += (*cp - '0');
29 }
30
31 return i;
32 }