.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sun Jul 25 10:54:03 1993 by Rik Faith (faith@cs.unc.edu) .\" Fixed typo, aeb, 950823 .\" 2002-02-22, joey, mihtjel: Added strtoull() .\" .\" Japanese Version Copyright (c) 1999 AKAMATSU, Kazuo .\" and 2006 Akihiro MOTOKI .\" all rights reserved. .\" Translated Thu Jan 31 18:00:00 JST 1999 .\" by AKAMATSU, Kazuo .\" Updated & Modified 2006-07-20, .\" Akihiro MOTOKI , LDP v2.36 .\" .\" WORD: base 基数 .\" .TH STRTOUL 3 2010-09-20 "GNU" "Linux Programmer's Manual" .SH 名前 .\"O strtoul, strtoull, strtouq \- convert a string to an unsigned long integer strtoul, strtoull, strtouq \- 文字列を unsigned long int に変換する .SH 書式 .nf .B #include .sp .BI "unsigned long int strtoul(const char *" nptr ", char **" endptr \ ", int " base ); .sp .BI "unsigned long long int strtoull(const char *" nptr ", char **" endptr , .BI " int " base ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .ad l .BR strtoull (): .RS 4 XOPEN_SOURCE\ >=\ 600 || _BSD_SOURCE || _SVID_SOURCE || _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L; .br or .I cc\ -std=c99 .RE .ad .SH 説明 .\"O The .\"O .BR strtoul () .\"O function converts the initial part of the string .\"O in \fInptr\fP to an .\"O .I "unsigned long int" .\"O value according to the .\"O given \fIbase\fP, which must be between 2 and 36 inclusive, or be .\"O the special value 0. .BR strtoul () 関数は、 \fInptr\fP の文字列の最初の部分を、 \fIbase\fP を基数として .I "unsigned long int" に変換する。 この \fIbase\fP は 2 から 36 までの値 あるいは特別な意味を持つ値 0 でなければならない。 .PP .\"O The string may begin with an arbitrary amount of white space (as .\"O determined by .\"O .BR isspace (3)) .\"O followed by a single optional \(aq+\(aq or \(aq\-\(aq .\"O sign. .\"O If \fIbase\fP is zero or 16, the string may then include a .\"O "0x" prefix, and the number will be read in base 16; otherwise, a .\"O zero \fIbase\fP is taken as 10 (decimal) unless the next character .\"O is \(aq0\(aq, in which case it is taken as 8 (octal). 文字列の先頭には、任意の数の空白があってもよく (空白は .BR ( isspace (3) で判定される) 、また数字の直前には \(aq+\(aq か \(aq\-\(aq の 符号があってもよい。 \fIbase\fP が 0 または 16 の場合には、 文字列の先頭に "0x" を置くことが でき、その場合には文字列は 16進数として扱われる。 これ以外の文字列で \fIbase\fP が 0 の場合は、 文字列が \(aq0\(aq で始まるときは 8進数として、 それ以外のときは 10進数として扱われる。 .PP .\"O The remainder of the string is converted to an .\"O .I "unsigned long int" .\"O value in the obvious manner, .\"O stopping at the first character which is not a .\"O valid digit in the given base. .\"O (In bases above 10, the letter \(aqA\(aq in .\"O either upper or lower case represents 10, \(aqB\(aq represents 11, and so .\"O forth, with \(aqZ\(aq representing 35.) 文字列の残りの部分は .I "unsigned long int" に変換されるが、基数に対して 有効でない数字が現れた時点で変換は終了する。(11進数以上では \(aqA\(aq は 大文字・小文字に関わらず 10 を表し、 \(aqB\(aq は 11 を表現し, 以下同様に、 \(aqZ\(aq は 35 を表す。) .PP .\"O If \fIendptr\fP is not NULL, .\"O .BR strtoul () .\"O stores the address of the .\"O first invalid character in \fI*endptr\fP. .\"O If there were no digits at .\"O all, .\"O .BR strtoul () .\"O stores the original value of \fInptr\fP in .\"O \fI*endptr\fP (and returns 0). .\"O In particular, if \fI*nptr\fP is not \(aq\\0\(aq but \fI**endptr\fP .\"O is \(aq\\0\(aq on return, the entire string is valid. \fIendptr\fP がヌル値 (NULL) でない場合、 .BR strtoul () は最初に不正な文字が現れたアドレスを \fI*endptr\fP に格納している。 文字列に有効な数字がひとつもなければ、 .BR strtoul () は \fInptr\fP の元の値を \fI*endptr\fP に代入する(そして 0 を返す)。 特に、 \fI*nptr\fP が \(aq\\0\(aq 以外で、返された \fI**endptr\fP が \(aq\\0\(aq ならば、文字列全体が有効だったことになる。 .PP .\"O The .\"O .BR strtoull () .\"O function works just like the .\"O .BR strtoul () .\"O function but returns an .\"O .I "unsigned long long int" .\"O value. .BR strtoull () 関数は .BR strtoul () 関数と同様だが、 .I "unsigned long long int" 型の値を返す。 .SH 返り値 .\"O The .\"O .BR strtoul () .\"O function returns either the result of the conversion .\"O or, if there was a leading minus sign, the negation of the result of the .\"O conversion represented as an unsigned value, .\"O unless the original (nonnegated) value would overflow; in .\"O the latter case, .\"O .BR strtoul () .\"O returns .\"O .B ULONG_MAX .\"O and sets \fIerrno\fP to .\"O .BR ERANGE . .BR strtoul () 関数は変換結果を返す。文字列がマイナス符号から始まっていた場 合は、(符号反転前の値がオーバーフローしていなければ) 変換結果を符号反転した 値を unsigned 型で返す。変換でオーバーフローが発生した場合は .B ULONG_MAX を返し、 .I errno に .B ERANGE を設定する。 .\"O Precisely the same holds for .\"O .BR strtoull () .\"O (with .\"O .B ULLONG_MAX .\"O instead of .\"O .BR ULONG_MAX ). .RB ( ULONG_MAX を .B ULLONG_MAX と読み替えれば) .BR strtoull () は .BR strtoul () と全く同じである。 .SH エラー .TP .B EINVAL .\"O (not in C99) .\"O The given .\"O .I base .\"O contains an unsupported value. (C99 にはない) 与えられた .I base がサポートされていない値である。 .TP .B ERANGE .\"O The resulting value was out of range. 文字列が数値の表現範囲外である。 .LP .\"O The implementation may also set \fIerrno\fP to \fBEINVAL\fP in case .\"O no conversion was performed (no digits seen, and 0 returned). 実装によっては、全く変換が行われなかった場合(全く数字が現れず、 0 が返される)、\fIerrno\fP に \fBEINVAL\fP がセットされるかもしれない。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O .BR strtoul () .\"O conforms to SVr4, C89, C99 and POSIX-2001, and .\"O .BR strtoull () .\"O to C99 and POSIX.1-2001. .BR strtoul () は SVr4, C89, C99 と POSIX-2001 に準拠している。 .BR strtoull () は C99 と POSIX.1-2001 に準拠している。 .\"O .SH NOTES .SH 注意 .\"O Since .\"O .BR strtoul () .\"O can legitimately return 0 or .\"O .B LONG_MAX .\"O .RB ( LLONG_MAX .\"O for .\"O .BR strtoull ()) .\"O on both success and failure, the calling program should set .\"O .I errno .\"O to 0 before the call, .\"O and then determine if an error occurred by checking whether .\"O .I errno .\"O has a nonzero value after the call. .B strtoul () からは成功、失敗どちらの場合でも 0 や .B LONG_MAX .RB ( strtoull () では .BR LLONG_MAX ) が返る可能性があるので、 プログラムは関数を呼び出す前に .I errno を 0 に設定し、呼び出し後に .I errno が 0 以外の値かどうかを確認しエラーが発生したかどうかを判断する 必要がある。 .\"O In locales other than the "C" locale, other strings may be accepted. "C" 以外のロケールの場合、その他の文字列も受け付けられるかもしれない。 .\"O (For example, the thousands separator of the current locale may be .\"O supported.) (例えば、現在のロケールの 1000 毎の区切り文字に対応しているかもしれない。) .LP .\"O BSD also has BSD には、 .sp .in +4n .nf .BI "u_quad_t strtouq(const char *" nptr ", char **" endptr ", int " base ); .sp .in -4n .fi .\"O with completely analogous definition. という完全に同様の定義を持つ関数がある。 .\"O Depending on the wordsize of the current architecture, this .\"O may be equivalent to .\"O .BR strtoull () .\"O or to .\"O .BR strtoul (). 使用中のアーキテクチャのワード長次第であるが、この関数は .BR strtoull () や .BR stroul () と等価な場合もありえる。 .\"O Negative values are considered valid input and are .\"O silently converted to the equivalent .\"O .I "unsigned long int" .\"O value. 負の値も正当な入力とみなされ、エラーもなく、 対応する .I "unsigned long int" 型の値に変換される。 .\"O .SH EXAMPLE .SH 例 .\"O See the example on the .\"O .BR strtol (3) .\"O manual page; .\"O the use of the functions described in this manual page is similar. .BR strtol (3) のマニュアルページの例を参照。 このページで説明した関数の使用方法も同様である。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR atof (3), .BR atoi (3), .BR atol (3), .BR strtod (3), .BR strtol (3)