strtol(3C) AT&T SYSTEM V strtol(3C)
NAME
strtol, strtoul - convert string to integer
SYNOPSIS
long strtol (str, ptr, base)
char *str, **ptr;
int base;
unsigned long strtoul (str, ptr, base)
char *str, **ptr;
int base;
DESCRIPTION
strtol returns as a long integer the value represented by
the character string pointed to by str. The string is
scanned up to the first character inconsistent with the
base. Leading ''white-space'' characters (as defined by
isspace in ctype(3C)) are ignored.
If the value of ptr is not (char **)NULL, a pointer to the
character terminating the scan is returned in the location
pointed to by ptr. If no integer can be formed, that loca-
tion is set to str, and zero is returned.
If base is greater than 1 and less than 36, it is used as
the base for conversion. After an optional leading sign,
leading zeros are ignored, and ''0x'' or ''0X'' is ignored
if base is 16.
If base is zero, the string itself determines the base as
follows: After an optional leading sign a leading zero indi-
cates octal conversion, and a leading ''0x'' or ''0X'' hexa-
decimal conversion. Otherwise, decimal conversion is used.
All other values of base are invalid.
Truncation from long to int can, of course, take place upon
assignment or by an explicit cast.
Strtoul behaves just like strtol except that it returns an
unsigned long, rather than a long.
DIAGNOSTICS
By default strtol ignores overflow conditions, except in
programs which are linked in one of the ANSI C compilation
modes and in programs linked in the 88open OCS-compliant
mode. This allows for upward compatibility for programs
that relied on strtol to translate constants that require
unsigned long representation before strtoul became avail-
able. Strtoul always detects overflow conditions.
Page 1 CX/UX Programmer's Reference Manual
strtol(3C) AT&T SYSTEM V strtol(3C)
When strtol detects an overflow, it returns either LONG_MAX
or LONG_MIN (depending upon the sign of str), and sets the
value of errno to ERANGE. If strtoul detects an overflow it
returns ULONG_MAX, and also sets the value of errno to
ERANGE.
If the value of base is invalid errno is set to EINVAL, and
0 is returned.
SEE ALSO
ctype(3C), scanf(3S), strtod(3C), atof(3C), atol(3C).
Page 2 CX/UX Programmer's Reference Manual