xntpd 3.3b from UDel
[unix-history] / contrib / xntpd / lib / atouint.c
CommitLineData
09169146
GW
1/* atouint.c,v 3.1 1993/07/06 01:07:42 jbj Exp
2 * atouint - convert an ascii string to an unsigned long, with error checking
3 */
4#include <sys/types.h>
5#include <ctype.h>
6
7#include "ntp_types.h"
8
9int
10atouint(str, uval)
11 const char *str;
12 U_LONG *uval;
13{
14 register U_LONG u;
15 register const char *cp;
16
17 cp = str;
18 if (*cp == '\0')
19 return 0;
20
21 u = 0;
22 while (*cp != '\0') {
23 if (!isdigit(*cp))
24 return 0;
25 if (u > 429496729 || (u == 429496729 && *cp >= '6'))
26 return 0; /* overflow */
27 u = (u << 3) + (u << 1);
28 u += *cp++ - '0'; /* ascii dependent */
29 }
30
31 *uval = u;
32 return 1;
33}