.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" %%%LICENSE_START(VERBATIM) .\" 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. .\" %%%LICENSE_END .\" .\" 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() .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" 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 .\" .TH STRTOUL 3 2020\-11\-01 GNU "Linux Programmer's Manual" .SH 名前 strtoul, strtoull, strtouq \- 文字列を unsigned long int に変換する .SH 書式 .nf \fB#include \fP .PP \fBunsigned long strtoul(const char *\fP\fInptr\fP\fB, char **\fP\fIendptr\fP\fB, int \fP\fIbase\fP\fB);\fP .PP \fBunsigned long long strtoull(const char *\fP\fInptr\fP\fB, char **\fP\fIendptr\fP\fB,\fP \fB int \fP\fIbase\fP\fB);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP .ad l \fBstrtoull\fP(): .RS 4 _ISOC99_SOURCE || || /* Glibc versions <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE .RE .ad .SH 説明 \fBstrtoul\fP() 関数は、 \fInptr\fP の文字列の最初の部分を、 \fIbase\fP を基数として \fIunsigned long\fP に変換する。 この \fIbase\fP は 2 から 36 までの値 あるいは特別な意味を持つ値 0 でなければならない。 .PP 文字列の先頭には、任意の数の空白があってもよく (空白は \fBisspace\fP(3) で判定される)、また数字の直前には \(aq+\(aq か \(aq\-\(aq の 符号があってもよい。 \fIbase\fP が 0 または 16 の場合には、文字列の先頭に "0x" を置くことが でき、その場合には文字列は 16進数として扱われる。 これ以外の文字列で \fIbase\fP が 0 の場合は、 文字列が \(aq0\(aq で始まるときは 8進数として、 それ以外のときは 10進数として扱われる。 .PP 文字列の残りの部分は \fIunsigned long\fP に変換されるが、基数に対して 有効でない数字が現れた時点で変換は終了する。(11進数以上では \(aqA\(aq は 大文字・小文字に関わらず 10 を表し、 \(aqB\(aq は 11 を表現し, 以下同様に、 \(aqZ\(aq は 35 を表す。) .PP \fIendptr\fP がヌル値 (NULL) でない場合、 \fBstrtoul\fP() は最初に不正な文字が現れたアドレスを \fI*endptr\fP に格納している。 文字列に有効な数字がひとつもなければ、 \fBstrtoul\fP() は \fInptr\fP の元の値を \fI*endptr\fP に代入する(そして 0 を返す)。 特に、 \fI*nptr\fP が \(aq\e0\(aq 以外で、返された \fI**endptr\fP が \(aq\e0\(aq ならば、文字列全体が有効だったことになる。 .PP \fBstrtoull\fP() 関数は \fBstrtoul\fP() 関数と同様だが、 \fIunsigned long long\fP 型の値を返す。 .SH 返り値 \fBstrtoul\fP() 関数は変換結果を返す。文字列がマイナス符号から始まっていた場 合は、(符号反転前の値がオーバーフローしていなければ) 変換結果を符号反転した 値を unsigned 型で返す。変換でオーバーフローが発生した場合は \fBULONG_MAX\fP を返し、 \fIerrno\fP に \fBERANGE\fP を設定する。 (\fBULONG_MAX\fP を \fBULLONG_MAX\fP と読み替えれば) \fBstrtoull\fP() は \fBstrtoul\fP() と全く同じである。 .SH エラー .TP \fBEINVAL\fP (C99 にはない) 指定された \fIbase\fP がサポートされていない値である。 .TP \fBERANGE\fP 結果の値が範囲外である。 .PP 実装によっては、変換が行われなかった場合 (数字がなく、0 を返した場合)、 \fIerrno\fP に \fBEINVAL\fP が設定される場合がある。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lbw32 lb lb l l l. インターフェース 属性 値 T{ \fBstrtoul\fP(), \fBstrtoull\fP(), \fBstrtouq\fP() T} Thread safety MT\-Safe locale .TE .SH 準拠 \fBstrtoul\fP(): POSIX.1\-2001, POSIX.1\-2008, C89, C99 SVr4. .PP \fBstrtoull\fP(): POSIX.1\-2001, POSIX.1\-2008, C99. .SH 注意 \fBstrtoul ()\fP からは成功、失敗どちらの場合でも 0 や \fBULONG_MAX\fP (\fBstrtoull\fP() では \fBULLONG_MAX\fP) が返る可能性があるので、 プログラムは関数を呼び出す前に \fIerrno\fP を 0 に設定し、呼び出し後に \fIerrno\fP が 0 以外の値かどうかを確認しエラーが発生したかどうかを判断する 必要がある。 .PP "C" 以外のロケールの場合、その他の文字列も受け付けられるかもしれない。 (例えば、現在のロケールの 1000 毎の区切り文字に対応しているかもしれない。) .PP BSD には、 .PP .in +4n .EX \fBu_quad_t strtouq(const char *\fP\fInptr\fP\fB, char **\fP\fIendptr\fP\fB, int \fP\fIbase\fP\fB);\fP .EE .in .PP という完全に同様の定義を持つ関数がある。 使用中のアーキテクチャーのワード長次第であるが、この関数は \fBstrtoull\fP() や \fBstroul\fP() と等価な場合もありえる。 .PP 負の値も正当な入力とみなされ、エラーもなく、 対応する \fIunsigned long\fP 型の値に変換される。 .SH 例 \fBstrtol\fP(3) のマニュアルページの例を参照。 このページで説明した関数の使用方法も同様である。 .SH 関連項目 \fBa64l\fP(3), \fBatof\fP(3), \fBatoi\fP(3), \fBatol\fP(3), \fBstrtod\fP(3), \fBstrtol\fP(3), \fBstrtoumax\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。