OSDN Git Service

5c2a8357bfbe5d8b3d50953ba6a40fe995b21921
[linuxjm/LDP_man-pages.git] / release / man3 / strtoul.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
27 .\" Modified Sun Jul 25 10:54:03 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Fixed typo, aeb, 950823
29 .\" 2002-02-22, joey, mihtjel: Added strtoull()
30 .\"
31 .\" Japanese Version Copyright (c) 1999 AKAMATSU, Kazuo
32 .\"                            and 2006 Akihiro MOTOKI
33 .\"         all rights reserved.
34 .\" Translated Thu Jan 31 18:00:00 JST 1999
35 .\"         by AKAMATSU, Kazuo
36 .\" Updated & Modified 2006-07-20,
37 .\"         Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
38 .\"
39 .\" WORD:       base            基数
40 .\"
41 .TH STRTOUL 3  2011-09-15 "GNU" "Linux Programmer's Manual"
42 .SH 名前
43 strtoul, strtoull, strtouq \- 文字列を unsigned long int に変換する
44 .SH 書式
45 .nf
46 .B #include <stdlib.h>
47 .sp
48 .BI "unsigned long int strtoul(const char *" nptr ", char **" endptr \
49 ", int " base );
50 .sp
51 .BI "unsigned long long int strtoull(const char *" nptr ", char **" endptr ,
52 .BI "                                int " base );
53 .fi
54 .sp
55 .in -4n
56 glibc 向けの機能検査マクロの要件
57 .RB ( feature_test_macros (7)
58 参照):
59 .in
60 .sp
61 .ad l
62 .BR strtoull ():
63 .RS 4
64 XOPEN_SOURCE\ >=\ 600 || _BSD_SOURCE || _SVID_SOURCE || _ISOC99_SOURCE ||
65 _POSIX_C_SOURCE\ >=\ 200112L;
66 .br
67 or
68 .I cc\ -std=c99
69 .RE
70 .ad
71 .SH 説明
72 .BR strtoul ()
73 関数は、 \fInptr\fP の文字列の最初の部分を、
74 \fIbase\fP を基数として
75 .I "unsigned long int"
76 に変換する。
77 この \fIbase\fP は 2 から 36 までの値
78 あるいは特別な意味を持つ値 0 でなければならない。
79 .PP
80 文字列の先頭には、任意の数の空白があってもよく (空白は
81 .BR ( isspace (3)
82 で判定される) 、また数字の直前には \(aq+\(aq か \(aq\-\(aq の
83 符号があってもよい。
84 \fIbase\fP が 0 または 16 の場合には、 文字列の先頭に "0x" を置くことが
85 でき、その場合には文字列は 16進数として扱われる。
86 これ以外の文字列で \fIbase\fP が 0 の場合は、
87 文字列が \(aq0\(aq で始まるときは 8進数として、
88 それ以外のときは 10進数として扱われる。
89 .PP
90 文字列の残りの部分は
91 .I "unsigned long int"
92 に変換されるが、基数に対して
93 有効でない数字が現れた時点で変換は終了する。(11進数以上では \(aqA\(aq は
94 大文字・小文字に関わらず 10 を表し、 \(aqB\(aq は 11 を表現し,
95 以下同様に、 \(aqZ\(aq は 35 を表す。)
96 .PP
97 \fIendptr\fP がヌル値 (NULL) でない場合、
98 .BR strtoul ()
99 は最初に不正な文字が現れたアドレスを
100 \fI*endptr\fP に格納している。
101 文字列に有効な数字がひとつもなければ、
102 .BR strtoul ()
103 は \fInptr\fP
104 の元の値を \fI*endptr\fP に代入する(そして 0 を返す)。
105 特に、 \fI*nptr\fP が \(aq\\0\(aq 以外で、返された \fI**endptr\fP が
106 \(aq\\0\(aq ならば、文字列全体が有効だったことになる。
107 .PP
108 .BR strtoull ()
109 関数は
110 .BR strtoul ()
111 関数と同様だが、
112 .I "unsigned long long int"
113 型の値を返す。
114 .SH 返り値
115 .BR strtoul ()
116 関数は変換結果を返す。文字列がマイナス符号から始まっていた場
117 合は、(符号反転前の値がオーバーフローしていなければ) 変換結果を符号反転した
118 値を unsigned 型で返す。変換でオーバーフローが発生した場合は
119 .B ULONG_MAX
120 を返し、
121 .I errno
122
123 .B ERANGE
124 を設定する。
125 .RB ( ULONG_MAX
126
127 .B ULLONG_MAX
128 と読み替えれば)
129 .BR strtoull ()
130
131 .BR strtoul ()
132 と全く同じである。
133 .SH エラー
134 .TP
135 .B EINVAL
136 (C99 にはない)
137 与えられた
138 .I base
139 がサポートされていない値である。
140 .TP
141 .B ERANGE
142 文字列が数値の表現範囲外である。
143 .LP
144 実装によっては、全く変換が行われなかった場合(全く数字が現れず、
145 0 が返される)、\fIerrno\fP に \fBEINVAL\fP がセットされるかもしれない。
146 .SH 準拠
147 .BR strtoul ()
148 は SVr4, C89, C99 と POSIX-2001 に準拠している。
149 .BR strtoull ()
150 は C99 と POSIX.1-2001 に準拠している。
151 .SH 注意
152 .B strtoul ()
153 からは成功、失敗どちらの場合でも 0 や
154 .B ULONG_MAX
155 .RB ( strtoull ()
156 では
157 .BR ULLONG_MAX )
158 が返る可能性があるので、
159 プログラムは関数を呼び出す前に
160 .I errno
161 を 0 に設定し、呼び出し後に
162 .I errno
163 が 0 以外の値かどうかを確認しエラーが発生したかどうかを判断する
164 必要がある。
165
166 "C" 以外のロケールの場合、その他の文字列も受け付けられるかもしれない。
167 (例えば、現在のロケールの 1000 毎の区切り文字に対応しているかもしれない。)
168 .LP
169 BSD には、
170 .sp
171 .in +4n
172 .nf
173 .BI "u_quad_t strtouq(const char *" nptr ", char **" endptr ", int " base );
174 .sp
175 .in -4n
176 .fi
177 という完全に同様の定義を持つ関数がある。
178 使用中のアーキテクチャのワード長次第であるが、この関数は
179 .BR strtoull ()
180
181 .BR stroul ()
182 と等価な場合もありえる。
183
184 負の値も正当な入力とみなされ、エラーもなく、
185 対応する
186 .I "unsigned long int"
187 型の値に変換される。
188 .SH 例
189 .BR strtol (3)
190 のマニュアルページの例を参照。
191 このページで説明した関数の使用方法も同様である。
192 .SH 関連項目
193 .BR atof (3),
194 .BR atoi (3),
195 .BR atol (3),
196 .BR strtod (3),
197 .BR strtol (3)