HP-UX Reference (11i v1 00/12) - 3 Library Functions N-Z (vol 7)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/nan.3m
________________________________________________________________
___ ___
s
strtol(3C) strtol(3C)
NAME
strtol(), atol(), atoi(), strtoul() - convert string to integer
SYNOPSIS
#include <stdlib.h>
long strtol(const char *str, char **ptr, int base);
long atol(const char *str);
int atoi(const char *str);
unsigned long strtoul(const char *str, char **ptr, int base);
DESCRIPTION
strtol() (strtoul()) converts the character string pointed to by str to long int (unsigned
long int
) representation. 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 no conversion
can take place, zero is returned.
If base is greater than or equal to 2 and less than or equal to 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 indicates octal conversion; a leading
0x or 0X hexadecimal conversion. Otherwise, decimal conver-
sion is used.
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, the location pointed to by ptr is set to str, and
zero is returned.
atol(str) is equivalent to strtol(str, (char **)NULL, 10).
atoi(
str) is equivalent to int strtol(str, (char **)NULL, 10).
APPLICATION USAGE
strtol(), strtoul(), atol() and atoi() are thread-safe and async-cancel-safe.
RETURN VALUE
Upon successful completion, all functions return the converted value, if any. If the correct value would
cause overflow, strtol() returns LONG_MAX or LONG_MIN (according to the sign of the value), and
sets errno to ERANGE; strtoul() returns ULONG_MAX and sets errno to ERANGE. Overflow con-
ditions are ignored by atol() and atoi().
For all other errors, zero is returned and errno is set to indicate the error.
ERRORS
strtol() and strtoul() fail and errno is set if any of the following conditions are encountered:
[EINVAL] The value of base is not supported.
[ERANGE] The value to be returned would have caused overflow.
AUTHOR
strtol(), atoi(), and atol(), were developed by OSF and HP.
SEE ALSO
ctype(3C), strtod(3C), scanf(3S).
STANDARDS CONFORMANCE
strtol(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, ANSI C
atoi(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
atol(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
strtoul(): AES, SVID3, XPG4, ANSI C
Section 3900 1 HP-UX Release 11i: December 2000
___
___