Obfuscate RCS ID matching so that CVS doesn't expand it.
[netbsd-mini2440.git] / dist / ntp / libntp / octtoint.c
bloba05ac9e476948decef338b6e35a1e47661af71f2
1 /* $NetBSD$ */
3 /*
4 * octtoint - convert an ascii string in octal to an unsigned
5 * long, with error checking
6 */
7 #include <stdio.h>
8 #include <ctype.h>
10 #include "ntp_stdlib.h"
12 int
13 octtoint(
14 const char *str,
15 u_long *ival
18 register u_long u;
19 register const char *cp;
21 cp = str;
23 if (*cp == '\0')
24 return 0;
26 u = 0;
27 while (*cp != '\0') {
28 if (!isdigit((int)*cp) || *cp == '8' || *cp == '9')
29 return 0;
30 if (u >= 0x20000000)
31 return 0; /* overflow */
32 u <<= 3;
33 u += *cp++ - '0'; /* ascii dependent */
35 *ival = u;
36 return 1;