strtol(3C) DG/UX R4.11MU05 strtol(3C)
NAME
strtol, strtoul, atol, atoi - convert string to integer
SYNOPSIS
#include <stdlib.h>
#include <limits.h>
long strtol (const char *str, char **ptr, int base);
unsigned long strtoul (const char *str, char **ptr, int base);
long atol (const char *str);
int atoi (const char *str);
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 location is set to str, and zero is
returned.
If base is between 2 and 36, inclusive, 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 indicates octal
conversion, and a leading ``0x'' or ``0X'' hexadecimal conversion.
Otherwise, decimal conversion is used.
Truncation from long to int can, of course, take place upon
assignment or by an explicit cast.
If the value represented by str would cause overflow, LONGMAX or
LONGMIN is returned (according to the sign of the value), and errno
is set to the value, ERANGE.
strtoul is similar to strtol except that strtoul returns as an
unsigned long integer the value represented by str. If the leading
character of str is a minus sign, strtoul will negate the converted
value. For example, an str set to "-3", will result in a return value
of 4294967293u from strtoul. If the value represented by str would
cause overflow, ULONGMAX is returned, and errno is set to the value,
ERANGE.
Except for behavior on error, atol(str) is equivalent to:
strtol(str, (char **)NULL, 10)
Except for behavior on error, atoi(str) is equivalent to:
(int) strtol(str, (char **)NULL, 10)
Return Values
If strtol is given a base greater than 36 or less than 2, it returns
0 and sets errno to EINVAL.
Considerations for Threads Programming
+---------+-----------------------------+
| | async- |
|function | reentrant cancel cancel |
| | point safe |
+---------+-----------------------------+
|atoi | Y N N |
|atol | Y N N |
|strtol | Y N N |
|strtoul | Y N N |
+---------+-----------------------------+
REFERENCES
reentrant(3), ctype(3C), strtod(3C), scanf(3S)
NOTICES
strtol no longer accepts values greater than LONGMAX as valid input.
Use strtoul instead.
Licensed material--property of copyright holder(s)