オープンソース・ソフトウェアの開発とダウンロード

CVS リポジトリの参照

Contents of /perldocjp/docs/perl/5.32.0/perlclib.pod

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Tue Jun 29 19:39:47 2021 UTC (2 years, 10 months ago) by argrath
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
5.32.0/*

1
2 =encoding euc-jp
3
4 =head1 NAME
5
6 =begin original
7
8 perlclib - Internal replacements for standard C library functions
9
10 =end original
11
12 perlclib - 標準 C ライブラリ関数の内部的な代用品
13
14 =head1 DESCRIPTION
15
16 =begin original
17
18 One thing Perl porters should note is that F<perl> doesn't tend to use that
19 much of the C standard library internally; you'll see very little use of,
20 for example, the F<ctype.h> functions in there. This is because Perl
21 tends to reimplement or abstract standard library functions, so that we
22 know exactly how they're going to operate.
23
24 =end original
25
26 Perl porters が注意するべき事のひとつは、F<perl> は内部で C 標準ライブラリを
27 あまり使わないようにしていると言うことです; 例えば、F<ctype.h> 関数は
28 ほとんど使われていないことに気付くでしょう。
29 これは、どのような操作をしようとしているかを正確に知るために、Perl は
30 標準ライブラリ関数を再実装したり抽象化したりしようとするからです。
31
32 =begin original
33
34 This is a reference card for people who are familiar with the C library
35 and who want to do things the Perl way; to tell them which functions
36 they ought to use instead of the more normal C functions.
37
38 =end original
39
40 これは C ライブラリに慣れていて Perl 方式で何かをしたい人々のための
41 リファレンスカードです; より普通の C 関数の代わりに使うべき関数を示します。
42
43 =head2 Conventions
44
45 (規約)
46
47 =begin original
48
49 In the following tables:
50
51 =end original
52
53 以下の表で:
54
55 =over 3
56
57 =item C<t>
58
59 =begin original
60
61 is a type.
62
63 =end original
64
65 は型です。
66
67 =item C<p>
68
69 =begin original
70
71 is a pointer.
72
73 =end original
74
75 はポインタです。
76
77 =item C<n>
78
79 =begin original
80
81 is a number.
82
83 =end original
84
85 は数値です。
86
87 =item C<s>
88
89 =begin original
90
91 is a string.
92
93 =end original
94
95 は文字列です。
96
97 =back
98
99 =begin original
100
101 C<sv>, C<av>, C<hv>, etc. represent variables of their respective types.
102
103 =end original
104
105 C<sv>, C<av>, C<hv> などはそれぞれ対応する型の変数です。
106
107 =head2 File Operations
108
109 (ファイル操作)
110
111 =begin original
112
113 Instead of the F<stdio.h> functions, you should use the Perl abstraction
114 layer. Instead of C<FILE*> types, you need to be handling C<PerlIO*>
115 types. Don't forget that with the new PerlIO layered I/O abstraction
116 C<FILE*> types may not even be available. See also the C<perlapio>
117 documentation for more information about the following functions:
118
119 =end original
120
121 F<stdio.h> 関数の代わりに、Perl 抽象層を使うべきです。
122 C<FILE*> 型の代わりに、C<PerlIO*> 型を扱う必要があります。
123 新しい PerlIO 層の I/O 抽象化では C<FILE*> 型は利用できないかも知れないことを
124 忘れないでください。
125 以下の関数に関するさらなる詳細については C<perlapio> 文書を
126 参照してください:
127
128 Instead Of: Use:
129
130 stdin PerlIO_stdin()
131 stdout PerlIO_stdout()
132 stderr PerlIO_stderr()
133
134 fopen(fn, mode) PerlIO_open(fn, mode)
135 freopen(fn, mode, stream) PerlIO_reopen(fn, mode, perlio) (Dep-
136 recated)
137 fflush(stream) PerlIO_flush(perlio)
138 fclose(stream) PerlIO_close(perlio)
139
140 =head2 File Input and Output
141
142 (ファイル入力と出力)
143
144 Instead Of: Use:
145
146 fprintf(stream, fmt, ...) PerlIO_printf(perlio, fmt, ...)
147
148 [f]getc(stream) PerlIO_getc(perlio)
149 [f]putc(stream, n) PerlIO_putc(perlio, n)
150 ungetc(n, stream) PerlIO_ungetc(perlio, n)
151
152 =begin original
153
154 Note that the PerlIO equivalents of C<fread> and C<fwrite> are slightly
155 different from their C library counterparts:
156
157 =end original
158
159 C<fread> と C<fwrite> の PerlIO の代用品は C ライブラリの対応物とは
160 少し違うことに注意してください:
161
162 fread(p, size, n, stream) PerlIO_read(perlio, buf, numbytes)
163 fwrite(p, size, n, stream) PerlIO_write(perlio, buf, numbytes)
164
165 fputs(s, stream) PerlIO_puts(perlio, s)
166
167 =begin original
168
169 There is no equivalent to C<fgets>; one should use C<sv_gets> instead:
170
171 =end original
172
173 C<fgets> の等価物はありません; 代わりに C<sv_gets> を使うべきです:
174
175 fgets(s, n, stream) sv_gets(sv, perlio, append)
176
177 =head2 File Positioning
178
179 (ファイル位置)
180
181 Instead Of: Use:
182
183 feof(stream) PerlIO_eof(perlio)
184 fseek(stream, n, whence) PerlIO_seek(perlio, n, whence)
185 rewind(stream) PerlIO_rewind(perlio)
186
187 fgetpos(stream, p) PerlIO_getpos(perlio, sv)
188 fsetpos(stream, p) PerlIO_setpos(perlio, sv)
189
190 ferror(stream) PerlIO_error(perlio)
191 clearerr(stream) PerlIO_clearerr(perlio)
192
193 =head2 Memory Management and String Handling
194
195 (メモリ管理と文字列操作)
196
197 Instead Of: Use:
198
199 t* p = malloc(n) Newx(p, n, t)
200 t* p = calloc(n, s) Newxz(p, n, t)
201 p = realloc(p, n) Renew(p, n, t)
202 memcpy(dst, src, n) Copy(src, dst, n, t)
203 memmove(dst, src, n) Move(src, dst, n, t)
204 memcpy(dst, src, sizeof(t)) StructCopy(src, dst, t)
205 memset(dst, 0, n * sizeof(t)) Zero(dst, n, t)
206 memzero(dst, 0) Zero(dst, n, char)
207 free(p) Safefree(p)
208
209 strdup(p) savepv(p)
210 strndup(p, n) savepvn(p, n) (Hey, strndup doesn't
211 exist!)
212
213 strstr(big, little) instr(big, little)
214 strcmp(s1, s2) strLE(s1, s2) / strEQ(s1, s2)
215 / strGT(s1,s2)
216 strncmp(s1, s2, n) strnNE(s1, s2, n) / strnEQ(s1, s2, n)
217
218 memcmp(p1, p2, n) memNE(p1, p2, n)
219 !memcmp(p1, p2, n) memEQ(p1, p2, n)
220
221 =begin original
222
223 Notice the different order of arguments to C<Copy> and C<Move> than used
224 in C<memcpy> and C<memmove>.
225
226 =end original
227
228 C<Copy> および C<Move> の引数の順番は C<memcpy> および C<memmove> と異なる
229 ことに注意してください。
230
231 =begin original
232
233 Most of the time, though, you'll want to be dealing with SVs internally
234 instead of raw C<char *> strings:
235
236 =end original
237
238 しかし、大抵の場合、生の C<char *> 文字列ではなく内部的に SV を
239 扱いたいでしょう:
240
241 strlen(s) sv_len(sv)
242 strcpy(dt, src) sv_setpv(sv, s)
243 strncpy(dt, src, n) sv_setpvn(sv, s, n)
244 strcat(dt, src) sv_catpv(sv, s)
245 strncat(dt, src) sv_catpvn(sv, s)
246 sprintf(s, fmt, ...) sv_setpvf(sv, fmt, ...)
247
248 =begin original
249
250 Note also the existence of C<sv_catpvf> and C<sv_vcatpvfn>, combining
251 concatenation with formatting.
252
253 =end original
254
255 連結とフォーマッティングを結合した C<sv_catpvf> および C<sv_vcatpvfn> が
256 あることにも注意してください。
257
258 =begin original
259
260 Sometimes instead of zeroing the allocated heap by using Newxz() you
261 should consider "poisoning" the data. This means writing a bit
262 pattern into it that should be illegal as pointers (and floating point
263 numbers), and also hopefully surprising enough as integers, so that
264 any code attempting to use the data without forethought will break
265 sooner rather than later. Poisoning can be done using the Poison()
266 macros, which have similar arguments to Zero():
267
268 =end original
269
270 時々、Newxz() を使って割り当てられたヒープをゼロにする代わりにデータに
271 「毒入れ」したいかもしれません。
272 これは、ポインタ(および浮動小数点数)として不正になり、できれば整数としても
273 十分に驚くべきビットパターンを書き込んで、考えなしにデータを使おうとする
274 コードが早めに壊れるようにすることです。
275 毒入れは Zero() と似たような引数を持つ Poison() マクロで行えます:
276
277 PoisonWith(dst, n, t, b) scribble memory with byte b
278 PoisonNew(dst, n, t) equal to PoisonWith(dst, n, t, 0xAB)
279 PoisonFree(dst, n, t) equal to PoisonWith(dst, n, t, 0xEF)
280 Poison(dst, n, t) equal to PoisonFree(dst, n, t)
281
282 =head2 Character Class Tests
283
284 (文字クラステスト)
285
286 =begin original
287
288 There are several types of character class tests that Perl implements.
289 The only ones described here are those that directly correspond to C
290 library functions that operate on 8-bit characters, but there are
291 equivalents that operate on wide characters, and UTF-8 encoded strings.
292 All are more fully described in L<perlapi/Character classification> and
293 L<perlapi/Character case changing>.
294
295 =end original
296
297 Perl が実装しているいくつか種類の文字クラステストがあります。
298 ここで記述しているのは 8 ビット文字を操作する C ライブライブラリに直接
299 対応しているもののみですが、ワイド文字、UTF-8 エンコード文字を操作する
300 等価物もあります。
301 全ては L<perlapi/Character classification> と
302 L<perlapi/Character case changing> でより完全に記述されています。
303
304 =begin original
305
306 The C library routines listed in the table below return values based on
307 the current locale. Use the entries in the final column for that
308 functionality. The other two columns always assume a POSIX (or C)
309 locale. The entries in the ASCII column are only meaningful for ASCII
310 inputs, returning FALSE for anything else. Use these only when you
311 B<know> that is what you want. The entries in the Latin1 column assume
312 that the non-ASCII 8-bit characters are as Unicode defines, them, the
313 same as ISO-8859-1, often called Latin 1.
314
315 =end original
316
317 後述する表に挙げられている C ライブラリルーチンは現在のロケールを基にした
318 値を返します。
319 この機能のためには最後の列のエントリを使ってください。
320 残りの二つの列は常に POSIX (あるいは C) ロケールを仮定します。
321 ASCII 列のエントリは ASCII 入力でのみ意味を持ち、それ以外では FALSE を
322 返します。
323 これが望んでいるものであると B<分かっている> 場合にのみこれを使ってください。
324 Latin1 列のエントリは、非 ASCII 8 ビット文字は Unicode が定義しているように、
325 ISO-8859-1 (しばしば Latin 1 と呼ばれます) であると仮定します。
326
327 =begin original
328
329 Instead Of: Use for ASCII: Use for Latin1: Use for locale:
330
331 =end original
332
333 元: ASCII 用: Latin1 用: ロケール用:
334
335 isalnum(c) isALPHANUMERIC(c) isALPHANUMERIC_L1(c) isALPHANUMERIC_LC(c)
336 isalpha(c) isALPHA(c) isALPHA_L1(c) isALPHA_LC(u )
337 isascii(c) isASCII(c) isASCII_LC(c)
338 isblank(c) isBLANK(c) isBLANK_L1(c) isBLANK_LC(c)
339 iscntrl(c) isCNTRL(c) isCNTRL_L1(c) isCNTRL_LC(c)
340 isdigit(c) isDIGIT(c) isDIGIT_L1(c) isDIGIT_LC(c)
341 isgraph(c) isGRAPH(c) isGRAPH_L1(c) isGRAPH_LC(c)
342 islower(c) isLOWER(c) isLOWER_L1(c) isLOWER_LC(c)
343 isprint(c) isPRINT(c) isPRINT_L1(c) isPRINT_LC(c)
344 ispunct(c) isPUNCT(c) isPUNCT_L1(c) isPUNCT_LC(c)
345 isspace(c) isSPACE(c) isSPACE_L1(c) isSPACE_LC(c)
346 isupper(c) isUPPER(c) isUPPER_L1(c) isUPPER_LC(c)
347 isxdigit(c) isXDIGIT(c) isXDIGIT_L1(c) isXDIGIT_LC(c)
348
349 tolower(c) toLOWER(c) toLOWER_L1(c) toLOWER_LC(c)
350 toupper(c) toUPPER(c) toUPPER_LC(c)
351
352 =begin original
353
354 To emphasize that you are operating only on ASCII characters, you can
355 append C<_A> to each of the macros in the ASCII column: C<isALPHA_A>,
356 C<isDIGIT_A>, and so on.
357
358 =end original
359
360 念を押しておくと、ASCII 文字のみを操作するなら、ASCII の列のそれぞれの
361 マクロに C<_A> を追加したものが使えます: C<isALPHA_A>, C<isDIGIT_A> などです。
362
363 =begin original
364
365 (There is no entry in the Latin1 column for C<isascii> even though there
366 is an C<isASCII_L1>, which is identical to C<isASCII>; the
367 latter name is clearer. There is no entry in the Latin1 column for
368 C<toupper> because the result can be non-Latin1. You have to use
369 C<toUPPER_uni>, as described in L<perlapi/Character case changing>.)
370
371 =end original
372
373 (C<isASCII> と等価な C<isASCII_L1> というものはありますが、C<isascii> の
374 Latin1 の列はありません; 前者の名前の方が明確です。
375 C<toupper> の Latin1 の列はありません; 結果は非 Latin1 に
376 なるかもしれないからです。
377 L<perlapi/Character case changing> に記述されている C<toUPPER_uni> を
378 使う必要があります。)
379
380 =head2 F<stdlib.h> functions
381
382 (F<stdlib.h> 関数)
383
384 Instead Of: Use:
385
386 atof(s) Atof(s)
387 atoi(s) grok_atoUV(s, &uv, &e)
388 atol(s) grok_atoUV(s, &uv, &e)
389 strtod(s, &p) Strtod(s, &p)
390 strtol(s, &p, n) Strtol(s, &p, b)
391 strtoul(s, &p, n) Strtoul(s, &p, b)
392
393 =begin original
394
395 Typical use is to do range checks on C<uv> before casting:
396
397 =end original
398
399 典型的な使用法は、キャストする前の C<uv> の範囲チェックです:
400
401 int i; UV uv;
402 char* end_ptr = input_end;
403 if (grok_atoUV(input, &uv, &end_ptr)
404 && uv <= INT_MAX)
405 i = (int)uv;
406 ... /* continue parsing from end_ptr */
407 } else {
408 ... /* parse error: not a decimal integer in range 0 .. MAX_IV */
409 }
410
411 =begin original
412
413 Notice also the C<grok_bin>, C<grok_hex>, and C<grok_oct> functions in
414 F<numeric.c> for converting strings representing numbers in the respective
415 bases into C<NV>s. Note that grok_atoUV() doesn't handle negative inputs,
416 or leading whitespace (being purposefully strict).
417
418 =end original
419
420 それぞれの基数で数値を表現している文字列を C<NV> に変換するための
421 F<numeric.c> にある C<grok_bin>, C<grok_hex>, C<grok_oct> 関数にも
422 注目してください。
423 grok_atoUV() は負の入力や銭湯の空白を扱わないことに注意してください
424 (意図的に厳密にしています)。
425
426 =begin original
427
428 Note that strtol() and strtoul() may be disguised as Strtol(), Strtoul(),
429 Atol(), Atoul(). Avoid those, too.
430
431 =end original
432
433 strtol() と strtoul() は Strtol(), Strtoul(), Atol(), Atoul() と言う形に
434 偽装しているかもしれないことに注意してください。
435 これらも避けてください。
436
437 =begin original
438
439 In theory C<Strtol> and C<Strtoul> may not be defined if the machine perl is
440 built on doesn't actually have strtol and strtoul. But as those 2
441 functions are part of the 1989 ANSI C spec we suspect you'll find them
442 everywhere by now.
443
444 =end original
445
446 理論的には、perl がビルドされたマシンに実際に strtol や strtoul がない
447 場合、C<Strtol> と C<Strtoul> は定義されないかもしれません。
448 しかしこれらの 2 関数は 1989 ANSI C 使用の一部なので、今のところどこでも
449 これらを見つけられると思われます。
450
451 int rand() double Drand01()
452 srand(n) { seedDrand01((Rand_seed_t)n);
453 PL_srand_called = TRUE; }
454
455 exit(n) my_exit(n)
456 system(s) Don't. Look at pp_system or use my_popen.
457
458 getenv(s) PerlEnv_getenv(s)
459 setenv(s, val) my_setenv(s, val)
460
461 =head2 Miscellaneous functions
462
463 (さまざまな関数)
464
465 =begin original
466
467 You should not even B<want> to use F<setjmp.h> functions, but if you
468 think you do, use the C<JMPENV> stack in F<scope.h> instead.
469
470 =end original
471
472 F<setjmp.h> 関数を使おうと B<思う> ことすらするべきではありませんが、もし
473 そう考えているなら、代わりに F<scope.h> の C<JMPENV> スタックを
474 使ってください。
475
476 =begin original
477
478 For C<signal>/C<sigaction>, use C<rsignal(signo, handler)>.
479
480 =end original
481
482 C<signal>/C<sigaction> については、C<rsignal(signo, handler)> を
483 使ってください。
484
485 =head1 SEE ALSO
486
487 L<perlapi>, L<perlapio>, L<perlguts>
488
489 =begin meta
490
491 Translate: SHIRAKATA Kentaro <argrath@ub32.org>
492 Status: completed
493
494 =end meta
495

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26