1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek and the American National Standards Committee X3, 6.\" on Information Processing Systems. 7.\" 8.\" %sccs.include.redist.man% 9.\" 10.\" @(#)strtoul.3 5.3 (Berkeley) 06/29/91 11.\" 12.Dd 13.Dt STRTOUL 3 14.Os 15.Sh NAME 16.Nm strtoul 17.Nd convert a string to an unsigned long integer 18.Sh SYNOPSIS 19.Fd #include <stdlib.h> 20.Fd #include <limits.h> 21.Fn strtoul "const char *nptr" "char **endptr" "int base" 22.Sh DESCRIPTION 23The 24.Fn strtoul 25function 26converts the string in 27.Fa nptr 28to an 29.Em unsigned long 30value according to the given 31.Fa base , 32which must be between 2 and 36 inclusive, 33or be the special value 0. 34.Pp 35The string may begin with an arbitrary amount of white space 36(as determined by 37.Xr isspace 3 ) 38followed by a single optional 39.Ql + 40or 41.Ql - 42sign. 43If 44.Fa base 45is zero or 16, 46the string may then include a 47.Ql 0x 48prefix, 49and the number will be read in base 16; otherwise, a zero 50.Fa base 51is taken as 10 (decimal) unless the next character is 52.Ql 0 , 53in which case it is taken as 8 (octal). 54.Pp 55The remainder of the string is converted to an 56.Em unsigned long 57value in the obvious manner, 58stopping at the end of the string 59or at the first character that does not produce a valid digit 60in the given base. 61(In bases above 10, the letter 62.Ql A 63in either upper or lower case 64represents 10, 65.Ql B 66represents 11, and so forth, with 67.Ql Z 68representing 35.) 69.Pp 70If 71.Fa endptr 72is non nil, 73.Fn strtoul 74stores the address of the first invalid character in 75.Fa *endptr . 76If there were no digits at all, however, 77.Fn strtoul 78stores the original value of 79.Fa nptr 80in 81.Fa *endptr . 82(Thus, if 83.Fa *nptr 84is not 85.Ql \e0 86but 87.Fa **endptr 88is 89.Ql \e0 90on return, the entire string was valid.) 91.Sh RETURN VALUES 92The 93.Fn strtoul 94function 95returns either the result of the conversion 96or, if there was a leading minus sign, 97the negation of the result of the conversion, 98unless the original (non-negated) value would overflow; 99in the latter case, 100.Fn strtoul 101returns 102.Dv ULONG_MAX 103and sets the global variable 104.Va errno 105to 106.Er ERANGE . 107.Sh ERRORS 108.Bl -tag -width [ERANGE] 109.It Bq Er ERANGE 110The given string was out of range; the value converted has been clamped. 111.El 112.Sh SEE ALSO 113.Xr strtol 3 114.Sh STANDARDS 115The 116.Fn strtoul 117function 118conforms to 119.St -ansiC . 120.Sh BUGS 121Ignores the current locale. 122