PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/ntp/libntp/octtoint.c

https://bitbucket.org/freebsd/freebsd-head/
C | 35 lines | 26 code | 5 blank | 4 comment | 10 complexity | ab12b8e29808821e212092c43de4a9cd MD5 | raw file
 1/*
 2 * octtoint - convert an ascii string in octal to an unsigned
 3 *	      long, with error checking
 4 */
 5#include <stdio.h>
 6#include <ctype.h>
 7
 8#include "ntp_stdlib.h"
 9
10int
11octtoint(
12	const char *str,
13	u_long *ival
14	)
15{
16	register u_long u;
17	register const char *cp;
18
19	cp = str;
20
21	if (*cp == '\0')
22	    return 0;
23
24	u = 0;
25	while (*cp != '\0') {
26		if (!isdigit((int)*cp) || *cp == '8' || *cp == '9')
27		    return 0;
28		if (u >= 0x20000000)
29		    return 0;	/* overflow */
30		u <<= 3;
31		u += *cp++ - '0';	/* ascii dependent */
32	}
33	*ival = u;
34	return 1;
35}