Sync usage with man page.
[netbsd-mini2440.git] / dist / ntp / libntp / atouint.c
blobf6bd2c5d1153b49601e255d47da7f6acae91be7f
1 /* $NetBSD$ */
3 /*
4 * atouint - convert an ascii string to an unsigned long, with error checking
5 */
6 #include <sys/types.h>
7 #include <ctype.h>
9 #include "ntp_types.h"
10 #include "ntp_stdlib.h"
12 int
13 atouint(
14 const char *str,
15 u_long *uval
18 register u_long u;
19 register const char *cp;
21 cp = str;
22 if (*cp == '\0')
23 return 0;
25 u = 0;
26 while (*cp != '\0') {
27 if (!isdigit((int)*cp))
28 return 0;
29 if (u > 429496729 || (u == 429496729 && *cp >= '6'))
30 return 0; /* overflow */
31 u = (u << 3) + (u << 1);
32 u += *cp++ - '0'; /* ascii dependent */
35 *uval = u;
36 return 1;