File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / ntp / libntp / atouint.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:08:38 2012 UTC (12 years ago) by misho
Branches: ntp, MAIN
CVS tags: v4_2_6p5p0, v4_2_6p5, HEAD
ntp 4.2.6p5

    1: /*
    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: #include "ntp_stdlib.h"
    9: 
   10: int
   11: atouint(
   12: 	const char *str,
   13: 	u_long *uval
   14: 	)
   15: {
   16: 	register u_long u;
   17: 	register const char *cp;
   18: 
   19: 	cp = str;
   20: 	if (*cp == '\0')
   21: 	    return 0;
   22: 
   23: 	u = 0;
   24: 	while (*cp != '\0') {
   25: 		if (!isdigit((int)*cp))
   26: 		    return 0;
   27: 		if (u > 429496729 || (u == 429496729 && *cp >= '6'))
   28: 		    return 0;	/* overflow */
   29: 		u = (u << 3) + (u << 1);
   30: 		u += *cp++ - '0';	/* ascii dependent */
   31: 	}
   32: 
   33: 	*uval = u;
   34: 	return 1;
   35: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>