OSDN Git Service

e705232a4c9ef0986e66178c0c7ecedd06899c47
[linuxjm/LDP_man-pages.git] / draft / man3 / glob.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
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 .\" License.
23 .\" Modified Wed Jul 28 11:12:17 1993 by Rik Faith (faith@cs.unc.edu)
24 .\" Modified Mon May 13 23:08:50 1996 by Martin Schulze (joey@linux.de)
25 .\" Modified 11 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
26 .\" Modified 990912 by aeb
27 .\" 2007-10-10 mtk
28 .\"     Added description of GLOB_TILDE_NOMATCH
29 .\"     Expanded the description of various flags
30 .\"     Various wording fixes.
31 .\"
32 .\" Japanese Version Copyright (c) 1998 Ken Wakasa all rights reserved.
33 .\" Translated 1998-06-24, Ken Wakasa <wakasa@iname.com>
34 .\" Updated 1999-01-04, Kentaro Shirakata <argrath@yo.rim.or.jp>
35 .\" Updated 2008-02-12, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
36 .\"
37 .TH GLOB 3  2007-10-10 "GNU" "Linux Programmer's Manual"
38 .\"O .SH NAME
39 .SH 名前
40 .\"O glob, globfree \- find pathnames matching a pattern, free memory from glob()
41 glob, globfree \- パターンにマッチするパス名を見付ける。glob() によっ
42 て確保されたメモリ領域を解放する。
43 .\"O .SH SYNOPSIS
44 .SH 書式
45 .nf
46 .B #include <glob.h>
47 .sp
48 .BI "int glob(const char *" pattern ", int " flags ,
49 .br
50 .BI "         int (*" errfunc ") (const char *" epath ", int " eerrno ),
51 .br
52 .BI "         glob_t *" pglob );
53 .br
54 .BI "void globfree(glob_t *" pglob );
55 .fi
56 .\"O .SH DESCRIPTION
57 .SH 説明
58 .\"O The
59 .\"O .BR glob ()
60 .\"O function searches for all the pathnames matching
61 .\"O .I pattern
62 .\"O according to the rules used by the shell (see
63 .\"O .BR glob (7)).
64 .BR glob ()
65 関数はシェルが用いているルール
66 .RB ( glob (7)
67 参照) に基づいてパターン
68 .I pattern
69 にマッチするすべてのパス名を検索する。
70 .\"O No tilde expansion or parameter substitution is done; if you want
71 .\"O these, use
72 .\"O .BR wordexp (3).
73 チルダ (~) の展開やパラメータ置換は行われない。それらを行いたい場合は
74 .BR wordexp (3)
75 を使うとよい。
76 .PP
77 .\"O The
78 .\"O .BR globfree ()
79 .\"O function frees the dynamically allocated storage from an earlier call
80 .\"O to
81 .\"O .BR glob ().
82 .BR globfree ()
83 関数は前に呼ばれた
84 .BR glob ()
85 により動的に確保された記憶領域を解放する。
86 .PP
87 .\"O The results of a
88 .\"O .BR glob ()
89 .\"O call are stored in the structure pointed to by
90 .\"O .IR pglob .
91 .\"O This structure is of type
92 .\"O .I glob_t
93 .\"O (declared in
94 .\"O .IR <glob.h> )
95 .\"O and includes the following elements defined by POSIX.2 (more may be
96 .\"O present as an extension):
97 .BR glob ()
98 の結果は
99 .I pglob
100 がポイントする構造体に返される。
101 .I pglob
102
103 .I glob_t
104 型の構造体である。
105 .I glob_t
106 型は
107 .I <glob.h>
108 内で宣言されており、以下の要素を含んでいる。これらの要素は POSIX.2 で定義
109 されている (さらに多くの要素が拡張として入っているかもしれない)。
110 .PP
111 .br
112 .in +4n
113 .nf
114 typedef struct {
115 .\"O     size_t   gl_pathc;    /* Count of paths matched so far  */
116 .\"O     char   **gl_pathv;    /* List of matched pathnames.  */
117 .\"O     size_t   gl_offs;     /* Slots to reserve in \fIgl_pathv\fP.  */
118     size_t   gl_pathc;    /* 今までにマッチしたパスの数 */
119     char   **gl_pathv;    /* マッチしたパス名のリスト */
120     size_t   gl_offs;     /* \fIgl_pathv\fP 内に確保するスロット数 */
121 } glob_t;
122 .fi
123 .in
124 .PP
125 .\"O Results are stored in dynamically allocated storage.
126 結果は動的に確保された記憶領域に入れられる。
127 .PP
128 .\"O The argument
129 .\"O .I flags
130 .\"O is made up of the bitwise OR of zero or more the following symbolic
131 .\"O constants, which modify the behavior of
132 .\"O .BR glob ():
133 パラメータ
134 .I flags
135 には以下の示す定数のうち、指定したいものをビットごとの OR で与える
136 (一つも
137 指定しなくてもよい)。これによって
138 .BR glob ()
139 の動作を変更できる。
140 .TP
141 .B GLOB_ERR
142 .\"O Return upon a read error (because a directory does not
143 .\"O have read permission, for example).
144 .\"O By default,
145 .\"O .BR glob ()
146 .\"O attempts carry on despite errors,
147 .\"O reading all of the directories that it can.
148 (例えば、ディレクトリに読み取り許可属性が無い場合などで)
149 読み取りエラーが発生した際に関数から戻る。
150 デフォルトでは、エラーに関わらず
151 読み取り可能なディレクトリを全てについて読み取りを実行しようとする。
152 .TP
153 .B GLOB_MARK
154 .\"O Append a slash to each path which corresponds to a directory.
155 ディレクトリに対応する各々のパスにスラッシュを付加する。
156 .TP
157 .B GLOB_NOSORT
158 .\"O Don't sort the returned pathnames.
159 .\"O The only reason to do this is to save processing time.
160 .\"O By default, the returned pathnames are sorted.
161 返されるパス名のソートを行わない。
162 ソートを行わない理由は、処理時間を節約するためだけである。
163 デフォルトでは、返されるパス名はソートされる。
164 .TP
165 .B GLOB_DOOFFS
166 .\"O Reserve
167 .\"O .I pglob\->gl_offs
168 .\"O slots at the beginning of the list of strings in
169 .\"O .IR pglob\->pathv .
170 .\"O The reserved slots contain NULL pointers.
171 .I pglob->pathv
172 の文字列リストの先頭に
173 .I pglob->gl_offs
174 スロット分の領域を予約する。
175 予約されたスロットには NULL ポインタが入る。
176 .TP
177 .B GLOB_NOCHECK
178 .\"O If no pattern matches, return the original pattern.
179 .\"O By default,
180 .\"O .BR glob ()
181 .\"O returns
182 .\"O .B GLOB_NOMATCH
183 .\"O if there are no matches.
184 マッチするパターンがなければ、元のパターンを返す。
185 デフォルトでは、
186 .BR glob ()
187 はマッチするパターンがなければ
188 .B GLOB_NOMATCH
189 を返す。
190 .TP
191 .B GLOB_APPEND
192 .\"O Append the results of this call to the vector of results
193 .\"O returned by a previous call to
194 .\"O .BR glob ().
195 .\"O Do not set this flag on the first invocation of
196 .\"O .BR glob ().
197 この呼び出しでの結果を直前の
198 .BR glob ()
199 の呼び出しで返された結果のベクトルに追加する。最初の
200 .BR glob ()
201 の呼び出しの際にはこのフラグを設定してはいけない。
202 .TP
203 .B GLOB_NOESCAPE
204 .\"O Don't allow backslash (\(aq\\\(aq) to be used as an escape
205 .\"O character.
206 .\"O Normally, a backslash can be used to quote the following character,
207 .\"O providing a mechanism to turn off the special meaning
208 .\"O metacharacters.
209 バックスラッシュ (\(aq\\\(aq) をエスケープ用文字として使用できない。
210 通常は、バックスラッシュを使って、次に続く文字をクォートすることで、
211 特別な意味を持つメタキャラクタを無効することができる。
212 .PP
213 .\"O .I flags
214 .\"O may also include any of the following, which are GNU
215 .\"O extensions and not defined by POSIX.2:
216 .I flags
217 には以下に示すものも指定できる。
218 これらは GNU で拡張されたもので、POSIX.2 では定義されていない。
219 .TP
220 .B GLOB_PERIOD
221 .\"O Allow a leading period to be matched by metacharacters.
222 .\"O By default, metacharacters can't match a leading period.
223 先頭のピリオドがメタキャラクタにマッチできるようにする。
224 デフォルトでは、メタキャラクタは先頭のピリオドにはマッチできない。
225 .TP
226 .B GLOB_ALTDIRFUNC
227 .\"O Use alternative functions
228 .\"O .IR pglob\->gl_closedir ,
229 .\"O .IR pglob\->gl_readdir ,
230 .\"O .IR pglob\->gl_opendir ,
231 .\"O .IR pglob\->gl_lstat ", and"
232 .\"O .I pglob\->gl_stat
233 .\"O for file system access instead of the normal library
234 .\"O functions.
235 ファイルシステムにアクセスする際に、通常のライブラリ関数の代わりに
236 代替関数
237 .IR pglob\->gl_closedir ,
238 .IR pglob\->gl_readdir ,
239 .IR pglob\->gl_opendir ,
240 .IR pglob\->gl_lstat ,
241 .I pglob\->gl_stat
242 が用いられる。
243 .TP
244 .B GLOB_BRACE
245 .\"O Expand
246 .\"O .BR csh (1)
247 .\"O style brace expressions of the form \fB{a,b}\fR.
248 .\"O Brace expressions can be nested.
249 .\"O Thus, for example, specifying the pattern
250 .\"O "{foo/{,cat,dog},bar}" would return the same results as four separate
251 .\"O .BR glob ()
252 .\"O calls using the strings:
253 .\"O "foo/",
254 .\"O "foo/cat",
255 .\"O "foo/dog",
256 .\"O and
257 .\"O "bar".
258 \fB{a,b}\fR
259 という形式の
260 .BR csh (1)
261 スタイルの括弧表現を展開する。
262 括弧表現は入れ子にすることができる。
263 したがって、例えば、"{foo/{,cat,dog},bar}" というパターンを
264 指定した場合に得られる結果は、
265 4つの文字列 "foo/", "foo/cat", "foo/dog", "bar" のそれぞれについて
266 .BR glob ()
267 を呼び出した場合と同じになる。
268 .TP
269 .B GLOB_NOMAGIC
270 .\"O If the pattern contains no metacharacters
271 .\"O then it should be returned as the sole matching word,
272 .\"O even if there is no file with that name.
273 パターンにメタキャラクタが含まれていない場合、
274 マッチ結果として指定されたパターンだけを返す。
275 パターンで指定された名前のファイルが存在しない場合であっても、
276 そのパターンが返される。
277 .TP
278 .B GLOB_TILDE
279 .\"O Carry out tilde expansion.
280 .\"O If a tilde (\(aq~\(aq) is the only character in the pattern,
281 .\"O or an initial tilde is followed immediately by a slash (\(aq/\(aq),
282 .\"O then the home directory of the caller is substituted for
283 .\"O the tilde.
284 .\"O If an initial tilde is followed by a username (e.g., "~andrea/bin"),
285 .\"O then the tilde and username are substituted by the home directory
286 .\"O of that user.
287 .\"O If the username is invalid, or the home directory cannot be
288 .\"O determined, then no substitution is performed.
289 チルダの展開を行う。
290 チルダ (\(aq~\(aq) がパターン内の唯一の文字の場合か、先頭のチルダの直後の文字が
291 スラッシュ (\(aq/\(aq) の場合、チルダを呼び出し者のホームディレクトリで置換する。
292 先頭のチルダにユーザ名が続く場合 (例えば "~andrea/bin")、
293 チルダとユーザ名をそのユーザのホームディレクトリで置換する。
294 ユーザ名が無効な場合やホームディレクトリが決定できない場合は、
295 置換は実行されない。
296 .TP
297 .B GLOB_TILDE_CHECK
298 .\"O This provides behavior similar to that of
299 .\"O .BR GLOB_TILDE .
300 .\"O The difference is that if the username is invalid, or the
301 .\"O home directory cannot be determined, then
302 .\"O instead of using the pattern itself as the name,
303 .\"O .BR glob ()
304 .\"O returns
305 .\"O .BR GLOB_NOMATCH
306 .\"O to indicate an error.
307 このフラグを指定すると
308 .B GLOB_TILDE
309 と同様の振舞いをする。
310 .B GLOB_TILDE
311 との違いは、ユーザ名が無効だった場合や
312 ホームディレクトリが決定できなかった場合に、
313 パターン自身を使用するのではなく、
314 .BR glob ()
315 がエラーを示す
316 .B GLOB_NOMATCH
317 を返すことである。
318 .TP
319 .B GLOB_ONLYDIR
320 .\"O This is a
321 .\"O .I hint
322 .\"O to
323 .\"O .BR glob ()
324 .\"O that the caller is interested only in directories that match the pattern.
325 .\"O If the implementation can easily determine file-type information,
326 .\"O then nondirectory files are not returned to the caller.
327 .\"O However, the caller must still check that returned files
328 .\"O are directories.
329 .\"O (The purpose of this flag is merely to optimize performance when
330 .\"O the caller is interested only in directories.)
331 このフラグは、
332 .BR glob ()
333 に対する「ヒント」であり、
334 呼び出し側がパターンにマッチするディレクトリにしか興味がないことを知らせる。
335 実装においてファイルの種別情報を簡単に決定できる場合は、ディレクトリでない
336 ファイルは呼び出し側に返されない。しかしながら、呼び出し側では、返された
337 ファイルリストがディレクトリかどうかを確認しなければならない。
338 (このフラグが存在するのは、呼び出し側がディレクトリにしか興味がない際に
339 性能を最適化する目的のためだけである。)
340 .PP
341 .\"O If
342 .\"O .I errfunc
343 .\"O is not NULL,
344 .\"O it will be called in case of an error with the arguments
345 .\"O .IR epath ,
346 .\"O a pointer to the path which failed, and
347 .\"O .IR eerrno ,
348 .\"O the value of
349 .\"O .I errno
350 .\"O as returned from one of the calls to
351 .\"O .BR opendir (3),
352 .\"O .BR readdir (3),
353 .\"O or
354 .\"O .BR stat (2).
355 .I errfunc
356 が NULL でなければ、
357 エラーが起こった場合には関数
358 .I errfunc
359 が呼び出される。関数の引数には、失敗したパス名
360 .I epath
361
362 .I errno
363 .RB ( opendir (3),
364 .BR readdir (3),
365 .BR stat (2).
366 のいずれかによってセットされた値) が与えられる。
367 .\"O If
368 .\"O .I errfunc
369 .\"O returns nonzero, or if
370 .\"O .B GLOB_ERR
371 .\"O is set,
372 .\"O .BR glob ()
373 .\"O will terminate after the call to
374 .\"O .IR errfunc .
375 .I errfunc
376 が 0 以外の値を返すかもしくは
377 .B GLOB_ERR
378 がセットされた場合
379 .BR glob ()
380
381 .I errfunc
382 の呼び出し後に終了する。
383 .PP
384 .\"O Upon successful return,
385 .\"O .I pglob\->gl_pathc
386 .\"O contains the number of matched pathnames and
387 .\"O .I pglob\->gl_pathv
388 .\"O contains a pointer to the list of pointers to matched pathnames.
389 .\"O The list of pointers is terminated by a NULL pointer.
390 呼び出しが成功して戻った場合
391 .I pglob\->gl_pathc
392 にはマッチしたパス名が含まれ、
393 .I pglob\->gl_pathv
394 はマッチしたパス名へのポインタのリストへのポインタとなる。
395 ポインタのリストは NULL ポインタで終端される。
396 .PP
397 .\"O It is possible to call
398 .\"O .BR glob ()
399 .\"O several times.
400 .\"O In that case, the
401 .\"O .B GLOB_APPEND
402 .\"O flag has to be set in
403 .\"O .I flags
404 .\"O on the second and later invocations.
405 .BR glob ()
406 を何度か続けて呼び出すことができる。その際2回目以降の呼び出しでは
407 .B GLOB_APPEND
408 フラグが
409 .I flags
410 に設定されていなければならない。
411 .PP
412 .\"O As a GNU extension,
413 .\"O .I pglob\->gl_flags
414 .\"O is set to the flags specified, \fBor\fRed with
415 .\"O .B GLOB_MAGCHAR
416 .\"O if any metacharacters were found.
417 GNU の拡張として、
418 .I pglob\->gl_flags
419 には指定したフラグがセットされる。もし一つでもメタキャラクタが見付かれば
420 このフラグと
421 .B GLOB_MAGCHAR
422 との \fBOR\fR を取った結果がセットされる。
423 .\"O .SH "RETURN VALUE"
424 .SH 返り値
425 .\"O On successful completion,
426 .\"O .BR glob ()
427 .\"O returns zero.
428 .\"O Other possible returns are:
429 呼び出しが成功して完了すると
430 .BR glob ()
431 は 0 を返す。
432 それ以外の返り値は以下の通り:
433 .TP
434 .B GLOB_NOSPACE
435 .\"O for running out of memory,
436 メモリを使い果たした
437 .TP
438 .B GLOB_ABORTED
439 .\"O for a read error, and
440 読み取りエラー
441 .TP
442 .B GLOB_NOMATCH
443 .\"O for no found matches.
444 一つもマッチしなかった
445 .\"O .SH "CONFORMING TO"
446 .SH 準拠
447 POSIX.2, POSIX.1-2001.
448 .\"O .SH BUGS
449 .\"O .SH NOTES
450 .SH 注意
451 .\"O The structure elements
452 .\"O .I gl_pathc
453 .\"O and
454 .\"O .I gl_offs
455 .\"O are declared as
456 .\"O .I size_t
457 .\"O in glibc 2.1, as they should be according to POSIX.2,
458 .\"O but are declared as
459 .\"O .I int
460 .\"O in libc4, libc5 and glibc 2.0.
461 glibc 2.1 では、
462 .I gl_pathc
463
464 .I gl_offs
465 は POSIX.2 で指定されているように
466 .I size_t
467 として宣言されている。
468 libc4, libc5, glibc 2.0 では、
469 .I int
470 として宣言されている。
471 .SH バグ
472 .\"O .BR glob ()
473 .\"O function may fail due to failure of underlying function calls, such as
474 .\"O .BR malloc (3)
475 .\"O or
476 .\"O .BR opendir (3).
477 .\"O These will store their error code in
478 .\"O .IR errno .
479 .BR glob ()
480 関数はその中で呼び出している
481 .BR malloc (3)
482
483 .BR opendir (3)
484 などの関数の呼び出しで失敗が起こると失敗する。
485 これにより
486 .I errno
487 にそのエラーコードが入る。
488 .\"O .SH EXAMPLE
489 .SH 例
490 .\"O One example of use is the following code, which simulates typing
491 .\"O .sp
492 .\"O .in +4n
493 .\"O ls \-l *.c ../*.c
494 .\"O .in
495 .\"O .sp
496 .\"O in the shell:
497 使用法の一例を以下に示す。以下はシェルで
498 .sp
499 .in +4n
500 ls \-l *.c ../*.c
501 .in
502 .sp
503 をタイプした場合をシミュレートしている。
504 .nf
505 .in +4n
506
507 glob_t globbuf;
508
509 globbuf.gl_offs = 2;
510 glob("*.c", GLOB_DOOFFS, NULL, &globbuf);
511 glob("../*.c", GLOB_DOOFFS | GLOB_APPEND, NULL, &globbuf);
512 globbuf.gl_pathv[0] = "ls";
513 globbuf.gl_pathv[1] = "\-l";
514 execvp("ls", &globbuf.gl_pathv[0]);
515 .in
516 .fi
517 .\"O .SH "SEE ALSO"
518 .SH 関連項目
519 .BR ls (1),
520 .BR sh (1),
521 .BR stat (2),
522 .BR exec (3),
523 .BR fnmatch (3),
524 .BR malloc (3),
525 .BR opendir (3),
526 .BR readdir (3),
527 .BR wordexp (3),
528 .BR glob (7)