1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
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
28 .\" Added description of GLOB_TILDE_NOMATCH
29 .\" Expanded the description of various flags
30 .\" Various wording fixes.
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
37 .TH GLOB 3 2007-10-10 "GNU" "Linux Programmer's Manual"
40 .\"O glob, globfree \- find pathnames matching a pattern, free memory from glob()
41 glob, globfree \- パターンにマッチするパス名を見付ける。glob() によっ
48 .BI "int glob(const char *" pattern ", int " flags ,
50 .BI " int (*" errfunc ") (const char *" epath ", int " eerrno ),
52 .BI " glob_t *" pglob );
54 .BI "void globfree(glob_t *" pglob );
60 .\"O function searches for all the pathnames matching
62 .\"O according to the rules used by the shell (see
70 .\"O No tilde expansion or parameter substitution is done; if you want
73 チルダ (~) の展開やパラメータ置換は行われない。それらを行いたい場合は
79 .\"O function frees the dynamically allocated storage from an earlier call
89 .\"O call are stored in the structure pointed to by
91 .\"O This structure is of type
95 .\"O and includes the following elements defined by POSIX.2 (more may be
96 .\"O present as an extension):
108 内で宣言されており、以下の要素を含んでいる。これらの要素は POSIX.2 で定義
109 されている (さらに多くの要素が拡張として入っているかもしれない)。
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 内に確保するスロット数 */
125 .\"O Results are stored in dynamically allocated storage.
126 結果は動的に確保された記憶領域に入れられる。
130 .\"O is made up of the bitwise OR of zero or more the following symbolic
131 .\"O constants, which modify the behavior of
135 には以下の示す定数のうち、指定したいものをビットごとの OR で与える
142 .\"O Return upon a read error (because a directory does not
143 .\"O have read permission, for example).
146 .\"O attempts carry on despite errors,
147 .\"O reading all of the directories that it can.
148 (例えば、ディレクトリに読み取り許可属性が無い場合などで)
149 読み取りエラーが発生した際に関数から戻る。
151 読み取り可能なディレクトリを全てについて読み取りを実行しようとする。
154 .\"O Append a slash to each path which corresponds to a directory.
155 ディレクトリに対応する各々のパスにスラッシュを付加する。
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.
162 ソートを行わない理由は、処理時間を節約するためだけである。
163 デフォルトでは、返されるパス名はソートされる。
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.
175 予約されたスロットには NULL ポインタが入る。
178 .\"O If no pattern matches, return the original pattern.
183 .\"O if there are no matches.
184 マッチするパターンがなければ、元のパターンを返す。
192 .\"O Append the results of this call to the vector of results
193 .\"O returned by a previous call to
195 .\"O Do not set this flag on the first invocation of
199 の呼び出しで返された結果のベクトルに追加する。最初の
201 の呼び出しの際にはこのフラグを設定してはいけない。
204 .\"O Don't allow backslash (\(aq\\\(aq) to be used as an escape
206 .\"O Normally, a backslash can be used to quote the following character,
207 .\"O providing a mechanism to turn off the special meaning
209 バックスラッシュ (\(aq\\\(aq) をエスケープ用文字として使用できない。
210 通常は、バックスラッシュを使って、次に続く文字をクォートすることで、
211 特別な意味を持つメタキャラクタを無効することができる。
214 .\"O may also include any of the following, which are GNU
215 .\"O extensions and not defined by POSIX.2:
218 これらは GNU で拡張されたもので、POSIX.2 では定義されていない。
221 .\"O Allow a leading period to be matched by metacharacters.
222 .\"O By default, metacharacters can't match a leading period.
223 先頭のピリオドがメタキャラクタにマッチできるようにする。
224 デフォルトでは、メタキャラクタは先頭のピリオドにはマッチできない。
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
235 ファイルシステムにアクセスする際に、通常のライブラリ関数の代わりに
237 .IR pglob\->gl_closedir ,
238 .IR pglob\->gl_readdir ,
239 .IR pglob\->gl_opendir ,
240 .IR pglob\->gl_lstat ,
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
252 .\"O calls using the strings:
263 したがって、例えば、"{foo/{,cat,dog},bar}" というパターンを
265 4つの文字列 "foo/", "foo/cat", "foo/dog", "bar" のそれぞれについて
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 パターンで指定された名前のファイルが存在しない場合であっても、
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
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
287 .\"O If the username is invalid, or the home directory cannot be
288 .\"O determined, then no substitution is performed.
290 チルダ (\(aq~\(aq) がパターン内の唯一の文字の場合か、先頭のチルダの直後の文字が
291 スラッシュ (\(aq/\(aq) の場合、チルダを呼び出し者のホームディレクトリで置換する。
292 先頭のチルダにユーザ名が続く場合 (例えば "~andrea/bin")、
293 チルダとユーザ名をそのユーザのホームディレクトリで置換する。
294 ユーザ名が無効な場合やホームディレクトリが決定できない場合は、
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,
305 .\"O .BR GLOB_NOMATCH
306 .\"O to indicate an error.
312 ホームディレクトリが決定できなかった場合に、
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.)
334 呼び出し側がパターンにマッチするディレクトリにしか興味がないことを知らせる。
335 実装においてファイルの種別情報を簡単に決定できる場合は、ディレクトリでない
336 ファイルは呼び出し側に返されない。しかしながら、呼び出し側では、返された
337 ファイルリストがディレクトリかどうかを確認しなければならない。
338 (このフラグが存在するのは、呼び出し側がディレクトリにしか興味がない際に
344 .\"O it will be called in case of an error with the arguments
346 .\"O a pointer to the path which failed, and
350 .\"O as returned from one of the calls to
351 .\"O .BR opendir (3),
352 .\"O .BR readdir (3),
359 が呼び出される。関数の引数には、失敗したパス名
366 のいずれかによってセットされた値) が与えられる。
369 .\"O returns nonzero, or if
373 .\"O will terminate after the call to
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.
394 はマッチしたパス名へのポインタのリストへのポインタとなる。
395 ポインタのリストは NULL ポインタで終端される。
397 .\"O It is possible to call
400 .\"O In that case, the
402 .\"O flag has to be set in
404 .\"O on the second and later invocations.
406 を何度か続けて呼び出すことができる。その際2回目以降の呼び出しでは
412 .\"O As a GNU extension,
413 .\"O .I pglob\->gl_flags
414 .\"O is set to the flags specified, \fBor\fRed with
416 .\"O if any metacharacters were found.
419 には指定したフラグがセットされる。もし一つでもメタキャラクタが見付かれば
422 との \fBOR\fR を取った結果がセットされる。
423 .\"O .SH "RETURN VALUE"
425 .\"O On successful completion,
428 .\"O Other possible returns are:
435 .\"O for running out of memory,
439 .\"O for a read error, and
443 .\"O for no found matches.
445 .\"O .SH "CONFORMING TO"
447 POSIX.2, POSIX.1-2001.
451 .\"O The structure elements
457 .\"O in glibc 2.1, as they should be according to POSIX.2,
458 .\"O but are declared as
460 .\"O in libc4, libc5 and glibc 2.0.
465 は POSIX.2 で指定されているように
468 libc4, libc5, glibc 2.0 では、
473 .\"O function may fail due to failure of underlying function calls, such as
476 .\"O .BR opendir (3).
477 .\"O These will store their error code in
484 などの関数の呼び出しで失敗が起こると失敗する。
490 .\"O One example of use is the following code, which simulates typing
493 .\"O ls \-l *.c ../*.c
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]);