43 lines
715 B
C
43 lines
715 B
C
#if !defined(lint) && defined(SCCSIDS)
|
|
static char sccsid[] = "@(#)atol.c 1.1 92/07/30 SMI"; /* from S5R2 2.1 */
|
|
#endif
|
|
|
|
/*LINTLIBRARY*/
|
|
#include <ctype.h>
|
|
|
|
#define ATOL
|
|
|
|
#ifdef ATOI
|
|
typedef int TYPE;
|
|
#define NAME atoi
|
|
#else
|
|
typedef long TYPE;
|
|
#define NAME atol
|
|
#endif
|
|
|
|
TYPE
|
|
NAME(p)
|
|
register char *p;
|
|
{
|
|
register TYPE n;
|
|
register int c, neg = 0;
|
|
|
|
if (!isdigit(c = *p)) {
|
|
while (isspace(c))
|
|
c = *++p;
|
|
switch (c) {
|
|
case '-':
|
|
neg++;
|
|
case '+': /* fall-through */
|
|
c = *++p;
|
|
}
|
|
if (!isdigit(c))
|
|
return (0);
|
|
}
|
|
for (n = '0' - c; isdigit(c = *++p); ) {
|
|
n *= 10; /* two steps to avoid unnecessary overflow */
|
|
n += '0' - c; /* accum neg to avoid surprises at MAX */
|
|
}
|
|
return (neg ? n : -n);
|
|
}
|