#include <stdlib.h>
unsigned long strtoul(const char *restrict nptr,
char **_Nullable restrict endptr, int base);
unsigned long long strtoull(const char *restrict nptr,
char **_Nullable restrict endptr, int base);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
strtoull():
_ISOC99_SOURCE
|| /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
The string may begin with an arbitrary amount of white space (as determined by isspace(3)) followed by a single optional '+' or '-' sign. If base is zero or 16, the string may then include a "0x" or "0X" prefix, and the number will be read in base 16; if base is zero or 2, the string may then include a "0b" or "0B" prefix, and the number will be read in base 2; otherwise, a zero base is taken as 10 (decimal) unless the next character is '0', in which case it is taken as 8 (octal).
The remainder of the string is converted to an unsigned long value in the obvious manner, stopping at the first character which is not a valid digit in the given base. (In bases above 10, the letter 'A' in either uppercase or lowercase represents 10, 'B' represents 11, and so forth, with 'Z' representing 35.)
If endptr is not NULL, and the base is supported, strtoul() stores the address of the first invalid character in *endptr. If there were no digits at all, strtoul() stores the original value of nptr in *endptr (and returns 0). In particular, if *nptr is not '\0' but **endptr is '\0' on return, the entire string is valid.
strtoull() 関数は strtoul() 関数と同様だが、 unsigned long long 型の値を返す。
実装によっては、変換が行われなかった場合 (数字がなく、0 を返した場合)、 errno に EINVAL が設定される場合がある。
| インターフェース | 属性 | 値 |
| strtoul(), strtoull(), strtouq() | Thread safety | MT-Safe locale |
BSD には、
u_quad_t strtouq(const char *nptr, char **endptr, int base);
という完全に同様の定義を持つ関数がある。 使用中のアーキテクチャーのワード長次第であるが、この関数は strtoull() や stroul() と等価な場合もありえる。