154359Sroberto/*
254359Sroberto * octtoint - convert an ascii string in octal to an unsigned
354359Sroberto *	      long, with error checking
454359Sroberto */
554359Sroberto#include <stdio.h>
654359Sroberto#include <ctype.h>
754359Sroberto
854359Sroberto#include "ntp_stdlib.h"
954359Sroberto
1054359Srobertoint
1154359Srobertoocttoint(
1254359Sroberto	const char *str,
1354359Sroberto	u_long *ival
1454359Sroberto	)
1554359Sroberto{
1654359Sroberto	register u_long u;
1754359Sroberto	register const char *cp;
1854359Sroberto
1954359Sroberto	cp = str;
2054359Sroberto
2154359Sroberto	if (*cp == '\0')
2254359Sroberto	    return 0;
2354359Sroberto
2454359Sroberto	u = 0;
2554359Sroberto	while (*cp != '\0') {
2654359Sroberto		if (!isdigit((int)*cp) || *cp == '8' || *cp == '9')
2754359Sroberto		    return 0;
2854359Sroberto		if (u >= 0x20000000)
2954359Sroberto		    return 0;	/* overflow */
3054359Sroberto		u <<= 3;
3154359Sroberto		u += *cp++ - '0';	/* ascii dependent */
3254359Sroberto	}
3354359Sroberto	*ival = u;
3454359Sroberto	return 1;
3554359Sroberto}
36