OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / release / man3 / strtol.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:53:39 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Added correction due to nsd@bbc.com (Nick Duffek) - aeb, 950610
29 .\"
30 .\" Japanese Version Copyright (c) 1999 AKAMATSU, Kazuo
31 .\"         all rights reserved.
32 .\" Translated Thu Jan 9 21:00:00 JST 1999
33 .\"         by AKAMATSU, Kazuo
34 .\" Updated Sun Apr  8 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
35 .\" Updated Sat Mar 23 JST 2002 by Kentaro Shirakata <argrath@ub32.org>
36 .\" Updated & Modified 2006-07-20,
37 .\"         Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
38 .\"
39 .\" WORD:       base            ´ð¿ô
40 .\"
41 .TH STRTOL 3  2007-07-26 "GNU" "Linux Programmer's Manual"
42 .SH Ì¾Á°
43 strtol, strtoll, strtoq \- Ê¸»úÎó¤ò long int ¤ËÊÑ´¹¤¹¤ë
44 .SH ½ñ¼°
45 .nf
46 .B #include <stdlib.h>
47 .sp
48 .BI "long int strtol(const char *" nptr ", char **" endptr ", int " base );
49 .sp
50 .BI "long long int strtoll(const char *" nptr ", char **" endptr \
51 ", int " base );
52 .fi
53 .sp
54 .in -4n
55 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
56 .RB ( feature_test_macros (7)
57 »²¾È):
58 .in
59 .sp
60 .ad l
61 .BR strtoll ():
62 XOPEN_SOURCE >= 600 || _BSD_SOURCE || _SVID_SOURCE || _ISOC99_SOURCE; or
63 .I cc\ -std=c99
64 .ad b
65 .SH ÀâÌÀ
66 .BR strtol ()
67 ´Ø¿ô¤Ï¡¢ \fInptr\fP ¤Îʸ»úÎó¤ÎºÇ½é¤ÎÉôʬ¤ò¡¢
68 \fIbase\fP ¤ò´ð¿ô¤È¤·¤Æ long int ¤ËÊÑ´¹¤¹¤ë¡£
69 ¤³¤Î \fIbase\fP ¤Ï 2 ¤«¤é 36 ¤Þ¤Ç¤ÎÃÍ
70 ¤¢¤ë¤¤¤ÏÆÃÊ̤ʰÕÌ£¤ò»ý¤ÄÃÍ 0 ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
71 .PP
72 ʸ»úÎó¤ÎÀèƬ¤Ë¤Ï¡¢Ç¤°Õ¤Î¿ô¤Î¶õÇò¤¬¤¢¤Ã¤Æ¤â¤è¤¯ (¶õÇò¤Ï
73 .BR isspace (3)
74 ¤ÇȽÄꤵ¤ì¤ë)¡¢¤Þ¤¿¿ô»ú¤ÎľÁ°¤Ë¤Ï \(aq+\(aq ¤« \(aq\-\(aq ¤Î
75 Éä¹æ¤¬¤¢¤Ã¤Æ¤â¤è¤¤¡£
76 \fIbase\fP ¤¬ 0 ¤Þ¤¿¤Ï 16 ¤Î¾ì¹ç¤Ë¤Ï¡¢Ê¸»úÎó¤ÎÀèƬ¤Ë "0x" ¤òÃÖ¤¯¤³¤È¤¬
77 ¤Ç¤­¡¢¤½¤Î¾ì¹ç¤Ë¤Ïʸ»úÎó¤Ï 16¿Ê¿ô¤È¤·¤Æ°·¤ï¤ì¤ë¡£
78 ¤³¤ì°Ê³°¤Îʸ»úÎó¤Ç \fIbase\fP ¤¬ 0 ¤Î¾ì¹ç¤Ï¡¢
79 ʸ»úÎ󤬠\(aq0\(aq ¤Ç»Ï¤Þ¤ë¤È¤­¤Ï 8¿Ê¿ô¤È¤·¤Æ¡¢
80 ¤½¤ì°Ê³°¤Î¤È¤­¤Ï 10¿Ê¿ô¤È¤·¤Æ°·¤ï¤ì¤ë¡£
81 .PP
82 ¿ô»ú¤òɽ¤¹Ê¸»úÎó¤Ï
83 .I long int
84 ¤ËÊÑ´¹¤µ¤ì¤ë¤¬¡¢´ð¿ô¤ËÂФ·¤Æ
85 Í­¸ú¤Ç¤Ê¤¤¿ô»ú¤¬¸½¤ì¤¿»þÅÀ¤ÇÊÑ´¹¤Ï½ªÎ»¤¹¤ë¡£(11¿Ê¿ô°Ê¾å¤Ç¤Ï \(aqA\(aq ¤Ï
86 Âçʸ»ú¡¦¾®Ê¸»ú¤Ë´Ø¤ï¤é¤º 10 ¤òɽ¤·¡¢ \(aqB\(aq ¤Ï 11 ¤òɽ¸½¤·¡¢
87 °Ê²¼Æ±Íͤˡ¢ \(aqZ\(aq ¤Ï 35 ¤òɽ¤¹¡£)
88 .PP
89 \fIendptr\fP ¤¬¥Ì¥ëÃÍ (NULL) ¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢ºÇ½é¤Ë¸½¤ì¤¿ÉÔÀµ¤Êʸ»ú¤¬
90 .BR strtol ()
91 ¤Ë¤è¤Ã¤Æ \fI*endptr\fP ¤ËÊݸ¤µ¤ì¤Æ¤¤¤ë¡£
92 ʸ»úÎó¤ËÍ­¸ú¤Ê¿ô»ú¤¬¤Ò¤È¤Ä¤â¤Ê¤±¤ì¤Ð¡¢
93 .BR strtol ()
94 ¤Ï \fInptr\fP
95 ¤Î¸µ¤ÎÃͤò \fI*endptr\fP ¤ËÂåÆþ¤¹¤ë (¤½¤·¤Æ 0 ¤òÊÖ¤¹)¡£
96 Æäˡ¢\fI*nptr\fP ¤¬ \(aq\\0\(aq °Ê³°¤Ç¡¢ÊÖ¤µ¤ì¤¿ \fI**endptr\fP ¤¬
97 \(aq\\0\(aq ¤Ê¤é¤Ð¡¢Ê¸»úÎóÁ´ÂΤ¬Í­¸ú¤À¤Ã¤¿¤³¤È¤Ë¤Ê¤ë¡£
98 .PP
99 .BR strtoll ()
100 ´Ø¿ô¤Ï
101 .BR strtol ()
102 ¤ÈƱÍͤÀ¤¬¡¢long long int ·¿¤ÎÃͤòÊÖ¤¹¡£
103 .SH ÊÖ¤êÃÍ
104 ¥¢¥ó¥À¡¼¥Õ¥í¡¼¤â¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤âµ¯¤­¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
105 .BR strtol ()
106 ´Ø¿ô¤Ï
107 ÊÑ´¹¤µ¤ì¤¿ÃͤòÊÖ¤¹¡£¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤·¤¿¾ì¹ç¤Ë¤Ï
108 .B LONG_MAX
109 ¤¬Ê֤ꡢ
110 ¥¢¥ó¥À¡¼¥Õ¥í¡¼¤·¤¿¾ì¹ç¤Ë¤Ï
111 .B LONG_MIN
112 ¤¬Ê֤롣¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¡¢
113 ¥¢¥ó¥À¡¼¥Õ¥í¡¼¤Î¤¤¤º¤ì¤Î¾ì¹ç¤Ë¤â
114 Âç°èÊÑ¿ô \fIerrno\fP ¤Ë¤Ï
115 .B ERANGE
116 ¤¬ÀßÄꤵ¤ì¤ë¡£
117 .BR strtoll ()
118 ¤âƱÍͤǤ¢¤ë¤¬¡¢
119 .B LONG_MIN
120 ¤È
121 .B LONG_MAX
122 ¤ÎÂå¤ï¤ê¤Ë
123 .B LLONG_MIN
124 ¤È
125 .B LLONG_MAX
126 ¤¬ÊÖ¤µ¤ì¤ë¡£
127 .SH ¥¨¥é¡¼
128 .TP
129 .B EINVAL
130 (C99 ¤Ë¤Ï¤Ê¤¤)
131 .I base
132 ¤¬Âбþ¤·¤Æ¤¤¤Ê¤¤ÃͤǤ¢¤ë¡£
133 .TP
134 .B ERANGE
135 ·ë²Ì¤ÎÃͤ¬Èϰϳ°¤Ç¤¢¤ë¡£
136 .LP
137 ¼ÂÁõ¤Ë¤è¤Ã¤Æ¤Ï¡¢ÊÑ´¹¤¬¹Ô¤ï¤ì¤Ê¤«¤Ã¤¿¾ì¹ç (¿ô»ú¤¬¤Ê¤¯¡¢0 ¤òÊÖ¤·¤¿¾ì¹ç)¡¢
138 \fIerrno\fP ¤Ë \fBEINVAL\fP ¤¬ÀßÄꤵ¤ì¤ë¾ì¹ç¤¬¤¢¤ë¡£
139 .SH ½àµò
140 .BR strtol ()
141 ¤Ï SVr4, 4.3BSD, C89, C99 ¤È POSIX.1-2001 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
142 .BR strtoll ()
143 ¤Ï C99 ¤È POSIX.1-2001 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
144 .SH Ãí°Õ
145 .B strtol ()
146 ¤«¤é¤ÏÀ®¸ù¡¢¼ºÇԤɤÁ¤é¤Î¾ì¹ç¤Ç¤â
147 0,
148 .BR LONG_MAX ,
149 .B LONG_MIN
150 .RB ( strtoll ()
151 ¤Ç¤Ï
152 .BR LLONG_MAX ,
153 .BR LLONG_MIN )
154 ¤¬ÊÖ¤ë²ÄǽÀ­¤¬¤¢¤ë¤Î¤Ç¡¢
155 ¥×¥í¥°¥é¥à¤Ï´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹Á°¤Ë
156 .I errno
157 ¤ò 0 ¤ËÀßÄꤷ¡¢¸Æ¤Ó½Ð¤·¸å¤Ë
158 .I errno
159 ¤¬ 0 °Ê³°¤ÎÃͤ«¤É¤¦¤«¤ò³Îǧ¤·¥¨¥é¡¼¤¬È¯À¸¤·¤¿¤«¤É¤¦¤«¤òȽÃǤ¹¤ë
160 ɬÍפ¬¤¢¤ë¡£
161
162 "C" °Ê³°¤Î¥í¥±¡¼¥ë¤Î¾ì¹ç¡¢¤½¤Î¾¤Îʸ»úÎó¤â¼õ¤±ÉÕ¤±¤é¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
163 (Î㤨¤Ð¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤Î 1000 Ëè¤Î¶èÀÚ¤êʸ»ú¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤¡£)
164 .LP
165 BSD ¤Ë¤Ï¡¢
166 .sp
167 .in +4n
168 .nf
169 .BI "quad_t strtoq(const char *" nptr ", char **" endptr ", int " base );
170 .sp
171 .in
172 .fi
173 ¤È¤¤¤¦´°Á´¤ËƱÍͤÎÄêµÁ¤ò»ý¤Ä´Ø¿ô¤¬¤¢¤ë¡£
174 »ÈÍÑÃæ¤Î¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Î¥ï¡¼¥ÉĹ¼¡Âè¤Ç¤¢¤ë¤¬¡¢¤³¤Î´Ø¿ô¤Ï
175 .BR strtoll ()
176 ¤«
177 .BR strtol ()
178 ¤ÈÅù²Á¤È¤Ê¤ë¤³¤È¤â¤¢¤ë¡£
179 .SH Îã
180 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï
181 .BR strtol ()
182 ¤Î»ÈÍÑÎã¤Ç¤¢¤ë¡£
183 ºÇ½é¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ë¤Ï
184 .BR strtol ()
185 ¤¬¿ô»ú¤È¤·¤Æ²ò¼á¤¹¤ëʸ»úÎó¤ò»ØÄꤹ¤ë¡£
186 (¾Êά²Äǽ¤Ê) ÆóÈÖÌܤΰú¤­¿ô¤Ë¤Ï
187 ÊÑ´¹¤Ë»ÈÍѤµ¤ì¤ë´ð¿ô¤ò»ØÄꤹ¤ë
188 (¤³¤Î°ú¤­¿ô¤Ï
189 .BR atoi (3)
190 ¤ò»È¤Ã¤Æ¿ôÃͤËÊÑ´¹¤µ¤ì¤ë¡£
191 .BR atoi (3)
192 ¤Ï
193 .BR strtol ()
194 ¤è¤ê¤â´Êñ¤Ê¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò»ý¤Ä´Ø¿ô¤Ç¡¢
195 ¤½¤ÎÃæ¤Ç¤Ï¥¨¥é¡¼¥Á¥§¥Ã¥¯¤Ï¹Ô¤ï¤ì¤Ê¤¤)¡£
196 ¤³¤Î¥×¥í¥°¥é¥à¤Î¼Â¹ÔÎã¤ò¤¤¤¯¤Ä¤«°Ê²¼¤Ë¼¨¤¹:
197 .in +4n
198 .nf
199
200 .RB "$" " ./a.out 123"
201 strtol() returned 123
202 .RB "$" " ./a.out \(aq    123\(aq"
203 strtol() returned 123
204 .RB "$" " ./a.out 123abc"
205 strtol() returned 123
206 Further characters after number: abc
207 .RB "$" " ./a.out 123abc 55"
208 strtol: Invalid argument
209 .RB "$" " ./a.out \(aq\(aq"
210 No digits were found
211 .RB "$" " ./a.out 4000000000"
212 strtol: Numerical result out of range
213 .fi
214 .in
215 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
216 \&
217 .nf
218 #include <stdlib.h>
219 #include <limits.h>
220 #include <stdio.h>
221 #include <errno.h>
222
223 int
224 main(int argc, char *argv[])
225 {
226     int base;
227     char *endptr, *str;
228     long val;
229
230     if (argc < 2) {
231         fprintf(stderr, "Usage: %s str [base]\\n", argv[0]);
232         exit(EXIT_FAILURE);
233     }
234
235     str = argv[1];
236     base = (argc > 2) ? atoi(argv[2]) : 10;
237
238     errno = 0;    /* To distinguish success/failure after call */
239     val = strtol(str, &endptr, base);
240
241     /* Check for various possible errors */
242
243     if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
244             || (errno != 0 && val == 0)) {
245         perror("strtol");
246         exit(EXIT_FAILURE);
247     }
248
249     if (endptr == str) {
250         fprintf(stderr, "No digits were found\\n");
251         exit(EXIT_FAILURE);
252     }
253
254     /* If we got here, strtol() successfully parsed a number */
255
256     printf("strtol() returned %ld\\n", val);
257
258     if (*endptr != \(aq\\0\(aq)        /* Not necessarily an error... */
259         printf("Further characters after number: %s\\n", endptr);
260
261     exit(EXIT_SUCCESS);
262 }
263 .fi
264 .SH ´ØÏ¢¹àÌÜ
265 .BR atof (3),
266 .BR atoi (3),
267 .BR atol (3),
268 .BR strtod (3),
269 .BR strtoul (3)