.\" $NetBSD: fts.3,v 1.13.2.1 1997/11/14 02:09:32 mrg Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)fts.3 8.5 (Berkeley) 4/16/94 .\" .\" 2007-12-08, mtk, Converted from mdoc to man macros .\" .\" Japanese Version Copyright (c) 2000 Yuichi SATO .\" all rights reserved. .\" Translated Tue Jul 11 19:02:58 JST 2000 .\" by Yuichi SATO .\" .\"WORD: hierarchy 階層 .\"WORD: traverse たどる .\"WORD: pointer ポインタ .\"WORD: restore 復元する .\"WORD: null-terminated NULL 終端された .\" .TH FTS 3 2007-12-28 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O fts, fts_open, fts_read, fts_children, fts_set, fts_close \- \ .\"O traverse a file hierarchy fts, fts_open, fts_read, fts_children, fts_set, fts_close \- \ ファイル階層をたどる .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .B #include .B #include .sp .BI "FTS *fts_open(char * const *" path_argv ", int " options ", " .BI " int (*" compar ")(const FTSENT **, const FTSENT **));" .sp .BI "FTSENT *fts_read(FTS *" ftsp ); .sp .BI "FTSENT *fts_children(FTS *" ftsp ", int " options ); .sp .BI "int fts_set(FTS *" ftsp ", FTSENT *" f ", int " options ); .sp .BI "int fts_close(FTS *" ftsp ); .fi .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O fts functions are provided for traversing .\"O file hierarchies. .\"O A simple overview is that the .\"O .BR fts_open () .\"O function returns a "handle" on a file hierarchy, which is then supplied to .\"O the other .\"O fts functions. fts 関数群は、ファイル階層をたどるために提供されている。 簡単に概略すると次のようになる。 .BR fts_open () 関数は、他の fts 関数群に渡すための、ファイル階層の「ハンドル」を返す。 .\"O The function .\"O .BR fts_read () .\"O returns a pointer to a structure describing one of the files in the file .\"O hierarchy. .\"O The function .\"O .BR fts_children () .\"O returns a pointer to a linked list of structures, each of which describes .\"O one of the files contained in a directory in the hierarchy. .\"O In general, directories are visited two distinguishable times; in preorder .\"O (before any of their descendants are visited) and in postorder (after all .\"O of their descendants have been visited). .\"O Files are visited once. .\"O It is possible to walk the hierarchy "logically" (ignoring symbolic links) .\"O or physically (visiting symbolic links), order the walk of the hierarchy or .\"O prune and/or revisit portions of the hierarchy. .BR fts_read () 関数は、ファイル階層中にある 1 つのファイルを記述する構造体へのポインタを返す。 .BR fts_children () 関数は、階層中のディレクトリにあるファイルを記述する構造体の リンクリストへのポインタを返す。 一般にディレクトリは、 preorder (正方向:下の階層のディレクトリをたどる前) と postorder (逆方向:下の階層のディレクトリをすべてたどった後) という、 異なる方向で 2 回たどられる。ファイルは 1 回たどられる。 ディレクトリ階層を「論理的に」(シンボリックリングを無視して) 移動することも、 物理的に (シンボリックリンクをたどって) 移動することも可能である。 また、階層中の移動の道筋を指示すること・ 余分なものを取り除くこと・階層の一部を再びたどることが可能である。 .PP .\"O Two structures are defined (and typedef'd) in the include file .\"O .IR . .\"O The first is .\"O .IR FTS , .\"O the structure that represents the file hierarchy itself. .\"O The second is .\"O .IR FTSENT , .\"O the structure that represents a file in the file .\"O hierarchy. .\"O Normally, an .\"O .I FTSENT .\"O structure is returned for every file in the file .\"O hierarchy. .\"O In this manual page, "file" and .\"O "FTSENT structure" .\"O are generally interchangeable. .\"O The .\"O .I FTSENT .\"O structure contains at least the following fields, which are .\"O described in greater detail below: 2 つの構造体がインクルードファイル .I で定義されている (さらに typedef されている)。 1 つ目は、ファイル階層そのものを表現する .I FTS 構造体である。 2 つ目は、ファイル階層中のファイルを表現する .I FTSENT 構造体である。 .I FTSENT 構造体は通常、ファイル階層中のすべてのファイルに対して返される。 この man ページでは、「ファイル」と .RI 「 FTSENT 構造体」を一般に読み変えることができる。 .I FTSENT 構造体は、少なくとも次のようなフィールドを持っており、 以下でより詳しく説明されている。 .in +4n .nf .\"O typedef struct _ftsent { .\"O unsigned short fts_info; /* flags for FTSENT structure */ .\"O char *fts_accpath; /* access path */ .\"O char *fts_path; /* root path */ .\"O short fts_pathlen; /* strlen(fts_path) */ .\"O char *fts_name; /* filename */ .\"O short fts_namelen; /* strlen(fts_name) */ .\"O short fts_level; /* depth (\-1 to N) */ .\"O int fts_errno; /* file errno */ .\"O long fts_number; /* local numeric value */ .\"O void *fts_pointer; /* local address value */ .\"O struct ftsent *fts_parent; /* parent directory */ .\"O struct ftsent *fts_link; /* next file structure */ .\"O struct ftsent *fts_cycle; /* cycle structure */ .\"O struct stat *fts_statp; /* stat(2) information */ .\"O } FTSENT; typedef struct _ftsent { unsigned short fts_info; /* FTSENT 構造体のためのフラグ */ char *fts_accpath; /* アクセスパス */ char *fts_path; /* ルートパス */ short fts_pathlen; /* fts_path の長さ */ char *fts_name; /* ファイル名 */ short fts_namelen; /* fts_name の長さ */ short fts_level; /* 深さ (\-1 〜 N) */ int fts_errno; /* ファイルのエラー番号 */ long fts_number; /* ローカルな番号 */ void *fts_pointer; /* ローカルなアドレス番号 */ struct ftsent *fts_parent; /* 親ディレクトリ */ struct ftsent *fts_link; /* 次のファイル構造体 */ struct ftsent *fts_cycle; /* 循環している構造体 */ struct stat *fts_statp; /* stat(2) の情報 */ } FTSENT; .fi .in .PP .\"O These fields are defined as follows: これらのフィールドは、次のように定義されている。 .\" .Bl -tag -width "fts_namelen" .TP 12 .IR fts_info .\"O One of the following flags describing the returned .\"O .I FTSENT .\"O structure and .\"O the file it represents. .\"O With the exception of directories without errors .\"O .RB ( FTS_D ), .\"O all of these .\"O entries are terminal, that is, they will not be revisited, nor will any .\"O of their descendants be visited. このフィールドは、返された .I FTSENT 構造体とファイルを説明する以下のフラグのいずれかを表している。 エラーのないディレクトリ .RB ( FTS_D ), の場合は例外として、それ以外のすべてのエントリは終端である。 つまり、エントリは再びたどられることもなく、 それより下の階層がたどられることもない。 .\" .Bl -tag -width FTS_DEFAULT .RS 12 .TP 12 .BR FTS_D .\"O A directory being visited in preorder. preorder でたどられるディレクトリ。 .TP .BR FTS_DC .\"O A directory that causes a cycle in the tree. .\"O (The .\"O .I fts_cycle .\"O field of the .\"O .I FTSENT .\"O structure will be filled in as well.) ツリーの中で循環しているディレクトリ。 .RI ( FTSENT 構造体の .I fts_cycle フィールドも同様に埋められる。) .TP .BR FTS_DEFAULT .\"O Any .\"O .I FTSENT .\"O structure that represents a file type not explicitly described .\"O by one of the other .\"O .I fts_info .\"O values. ファイルタイプを表現する .I FTSENT 構造体が、 .I fts_info の他のいずれかの値で明示的に説明されていない。 .TP .BR FTS_DNR .\"O A directory which cannot be read. .\"O This is an error return, and the .\"O .I fts_errno .\"O field will be set to indicate what caused the error. 読み込みができないディレクトリ。 これはエラーの場合の返り値であり、 何がエラーを起こしたかを示すために .I fts_errno フィールドが設定される。 .TP .BR FTS_DOT .\"O A file named .\"O "." .\"O or .\"O ".." .\"O which was not specified as a filename to .\"O .BR fts_open () .\"O (see .\"O .BR FTS_SEEDOT ). .BR fts_open () へのファイル名として指定されなかった "." または ".." という名前のファイル .RB ( FTS_SEEDOT を参照すること)。 .TP .BR FTS_DP .\"O A directory being visited in postorder. .\"O The contents of the .\"O .I FTSENT .\"O structure will be unchanged from when .\"O it was returned in preorder, that is, with the .\"O .I fts_info .\"O field set to .\"O .BR FTS_D . postorder でたどられるディレクトリ。 .I FTSENT 構造体の内容は、preorder のときに返された状態 (つまり、 .I fts_info フィールドが .B FTS_D に設定されている状態) から変更されない。 .TP .B FTS_ERR .\"O This is an error return, and the .\"O .I fts_errno .\"O field will be set to indicate what caused the error. これはエラーの場合の返り値であり、 .I fts_errno フィールドは、何がエラーを起こしたかを示す値に設定される。 .TP .B FTS_F .\"O A regular file. 通常のファイル。 .TP .B FTS_NS .\"O A file for which no .\"O .BR stat (2) .\"O information was available. .\"O The contents of the .\"O .I fts_statp .\"O field are undefined. .\"O This is an error return, and the .\"O .I fts_errno .\"O field will be set to indicate what caused the error. .BR stat (2) 情報が得られなかったファイル。 .I fts_statp フィールドの内容は定義されない。 これはエラーの場合の返り値であり、 .I fts_errno フィールドは、何がエラーを起こしたかを示す値に設定される。 .TP .B FTS_NSOK .\"O A file for which no .\"O .BR stat (2) .\"O information was requested. .\"O The contents of the .\"O .I fts_statp .\"O field are undefined. .BR stat (2) 情報が要求されなかったファイル。 .I fts_statp フィールドの内容は定義されない。 .TP .B FTS_SL .\"O A symbolic link. シンボリックリンク。 .TP .B FTS_SLNONE .\"O A symbolic link with a non-existent target. .\"O The contents of the .\"O .I fts_statp .\"O field reference the file characteristic information for the symbolic link .\"O itself. リンク先の存在しないシンボリックリンク。 .I fts_statp フィールドの内容は、シンボリックリンクそのもののファイル特性情報を参照する。 .\" .El .RE .TP .IR fts_accpath .\"O A path for accessing the file from the current directory. 現在のディレクトリからファイルにアクセスするためのパス。 .TP .IR fts_path .\"O The path for the file relative to the root of the traversal. .\"O This path contains the path specified to .\"O .BR fts_open () .\"O as a prefix. 階層をたどるときのルートからみたファイルの相対的なパス。 このパスには、 .BR fts_open () に指定したパスがプレフィックスとして含まれる。 .TP .IR fts_pathlen .\"O The length of the string referenced by .\"O .IR fts_path . .I fts_path で参照される文字列の長さ。 .TP .IR fts_name .\"O The name of the file. ファイルの名前。 .TP .IR fts_namelen .\"O The length of the string referenced by .\"O .IR fts_name . .I fts_name で参照される文字列の長さ。 .TP .IR fts_level .\"O The depth of the traversal, numbered from \-1 to N, where this file .\"O was found. .\"O The .\"O .I FTSENT .\"O structure representing the parent of the starting point (or root) .\"O of the traversal is numbered \-1, and the .\"O .I FTSENT .\"O structure for the root .\"O itself is numbered 0. 階層をたどって、このファイルがみつかった深さ。 \-1 〜 N の数値で表される。 階層をたどるときの出発点 (ルート) の親ディレクトリを表す .I FTSENT 構造体では \-1 となる。 また、ルート自身の .I FTSENT 構造体では 0 になる。 .TP .IR fts_errno .\"O Upon return of a .\"O .I FTSENT .\"O structure from the .\"O .BR fts_children () .\"O or .\"O .BR fts_read () .\"O functions, with its .\"O .I fts_info .\"O field set to .\"O .BR FTS_DNR , .\"O .B FTS_ERR .\"O or .\"O .BR FTS_NS , .\"O the .\"O .I fts_errno .\"O field contains the value of the external variable .\"O .I errno .\"O specifying the cause of the error. .\"O Otherwise, the contents of the .\"O .I fts_errno .\"O field are undefined. 関数 .BR fts_children () と .BR fts_read () から返される .I FTSENT 構造体の .I fts_info フィールドが .BR FTS_DNR , .BR FTS_ERR , .B FTS_NS に設定されている場合、 .I fts_errno フィールドにはエラーの原因を示す外部変数 .I errno の値が入る。 それ以外の場合、 .I fts_errno フィールドの内容は定義されない。 .TP .IR fts_number .\"O This field is provided for the use of the application program and is .\"O not modified by the .\"O fts functions. .\"O It is initialized to 0. このフィールドは、アプリケーションプログラムから使用するために提供され、 fts 関数群では変更されない。 このフィールドは 0 で初期化される。 .TP .IR fts_pointer .\"O This field is provided for the use of the application program and is .\"O not modified by the .\"O fts functions. .\"O It is initialized to .\"O .BR NULL . このフィールドは、アプリケーションプログラムから使用するために提供され、 fts 関数群では変更されない。 このフィールドは .B NULL で初期化される。 .TP .IR fts_parent .\"O A pointer to the .\"O .I FTSENT .\"O structure referencing the file in the hierarchy .\"O immediately above the current file, that is, the directory of which this .\"O file is a member. .\"O A parent structure for the initial entry point is provided as well, .\"O however, only the .\"O .IR fts_level , .\"O .I fts_number .\"O and .\"O .I fts_pointer .\"O fields are guaranteed to be initialized. 現在のファイルのすぐ上の階層にあるファイル (つまり、現在のファイルがメンバーになっているディレクトリ) を参照する .I FTSENT 構造体へのポインタ。 最初の出発点に対しても、親となる構造体は与えられる。 しかし、 .IR fts_level , .IR fts_number , .I fts_pointer フィールドのみの初期化しか保証されない。 .TP .IR fts_link .\"O Upon return from the .\"O .BR fts_children () .\"O function, the .\"O .I fts_link .\"O field points to the next structure in the NULL-terminated linked list of .\"O directory members. .\"O Otherwise, the contents of the .\"O .I fts_link .\"O field are undefined. .BR fts_children () から返される場合、 .I fts_link フィールドはディレクトリメンバーの NUL 終端されたリンクリストの形式で、 次の構造体を指し示す。 それ以外の場合、 .I fts_link フィールドは定義されない。 .TP .IR fts_cycle .\"O If a directory causes a cycle in the hierarchy (see .\"O .BR FTS_DC ), .\"O either because .\"O of a hard link between two directories, or a symbolic link pointing to a .\"O directory, the .\"O .I fts_cycle .\"O field of the structure will point to the .\"O .I FTSENT .\"O structure in the hierarchy that references the same file as the current .\"O .I FTSENT .\"O structure. .\"O Otherwise, the contents of the .\"O .I fts_cycle .\"O field are undefined. 2 つのディレクトリにハードリンクが張られているため、 または、シンボリックリンクがあるディレクトリを指しているために、 ディレクトリが循環する階層構造を作っている場合 .RB ( FTS_DC を参照)、 構造体の .I fts_cycle フィールドは、階層中で現在の .I FTSENT 構造体と同じファイルを参照している .I FTSENT 構造体を指し示す。 それ以外の場合、 .I fts_cycle フィールドは定義されない。 .TP .IR fts_statp .\"O A pointer to .\"O .BR stat (2) .\"O information for the file. このファイルの .BR stat (2) 情報へのポインタ。 .\" .El .PP .\"O A single buffer is used for all of the paths of all of the files in the .\"O file hierarchy. .\"O Therefore, the .\"O .I fts_path .\"O and .\"O .I fts_accpath .\"O fields are guaranteed to be .\"O null-terminated .\"O .I only .\"O for the file most recently returned by .\"O .BR fts_read (). .\"O To use these fields to reference any files represented by other .\"O .I FTSENT .\"O structures will require that the path buffer be modified using the .\"O information contained in that .\"O .I FTSENT .\"O structure's .\"O .I fts_pathlen .\"O field. .\"O Any such modifications should be undone before further calls to .\"O .BR fts_read () .\"O are attempted. .\"O The .\"O .I fts_name .\"O field is always .\"O null-terminated. ファイル階層中のすべてのファイルのパスに対して、 ただ 1 つのバッファーが使われる。 したがって、 .I fts_path と .I fts_accpath フィールドは、 .BR fts_read () によって返された最も新しいファイルに対して「のみ」 NULL 終端されることが保証される。 これらのフィールドを、他の .I FTSENT 構造体で表現されるファイルを参照するために使うには、 .I FTSENT 構造体の .I fts_pathlen フィールドにある情報を使ってパスのバッファーを修正する必要がある。 これらの修正は、さらに .BR fts_read () を呼び出そうとする場合には、元に戻しておかなければならない。 .I fts_name フィールドは、常に .B NUL 終端される。 .SS fts_open() .\"O The .\"O .BR fts_open () .\"O function takes a pointer to an array of character pointers naming one .\"O or more paths which make up a logical file hierarchy to be traversed. .\"O The array must be terminated by a .\"O .B NULL .\"O pointer. .BR fts_open () 関数は、文字列ポインタの配列へのポインタを引き数に取る。 この文字列ポインタは、論理ファイル階層をつくる 1 つ以上のパスの名前になる。 配列は、 .B NULL ポインタで終端されなければならない。 .PP .\"O There are .\"O a number of options, at least one of which (either .\"O .B FTS_LOGICAL .\"O or .\"O .BR FTS_PHYSICAL ) .\"O must be specified. .\"O The options are selected by .\"O .IR or ing .\"O the following values: 多くのオプションがあり、少なくとも 1 つ .RB ( FTS_LOGICAL または .BR FTS_PHYSICAL ) が指定されなければならない。 次のオプションが .I or をとって選択される。 .\" .Bl -tag -width "FTS_PHYSICAL" .TP .B FTS_COMFOLLOW .\"O This option causes any symbolic link specified as a root path to be .\"O followed immediately whether or not .\"O .B FTS_LOGICAL .\"O is also specified. このオプションは、 .B FTS_LOGICAL の指定にかかわらず、 ルートパスに指定されたシンボリックリンクをすぐにたどらせる。 .TP .B FTS_LOGICAL .\"O This option causes the .\"O fts routines to return .\"O .I FTSENT .\"O structures for the targets of symbolic links .\"O instead of the symbolic links themselves. .\"O If this option is set, the only symbolic links for which .\"O .I FTSENT .\"O structures .\"O are returned to the application are those referencing non-existent files. .\"O Either .\"O .B FTS_LOGICAL .\"O or .\"O .B FTS_PHYSICAL .\"O .I must .\"O be provided to the .\"O .BR fts_open () .\"O function. このオプションは、 fts ルーチンにシンボリックリンクそのものではなく、 シンボリックリンクが指しているファイルの .I FTSENT 構造体を返させる。 このオプションが設定された場合、 .I FTSENT 構造体がアプリケーションに返されるような シンボリックリンクのみが、存在しないファイルを参照している。 .B FTS_LOGICAL または .B FTS_PHYSICAL のどちらかを、 .BR fts_open () 関数に与えなければ「ならない」。 .TP .B FTS_NOCHDIR .\"O As a performance optimization, the .\"O fts functions change directories as they walk the file hierarchy. .\"O This has the side-effect that an application cannot rely on being .\"O in any particular directory during the traversal. .\"O The .\"O .B FTS_NOCHDIR .\"O option turns off this optimization, and the .\"O fts functions will not change the current directory. .\"O Note that applications should not themselves change their current directory .\"O and try to access files unless .\"O .B FTS_NOCHDIR .\"O is specified and absolute .\"O pathnames were provided as arguments to .\"O .BR fts_open (). パフォーマンスの最適化のため、 fts 関数群はファイル階層をたどるときディレクトリを変える。 これには、階層をたどっている間は アプリケーションがある特定のディレクトリにいるということに 依存できない、という副作用がある。 .B FTS_NOCHDIR オプションで最適化を無効にすると、 fts 関数群は現在のディレクトリを変更しない。 .B FTS_NOCHDIR が指定され、かつ .BR fts_open () の引き数として絶対パス名が与えられたとき以外、アプリケーションは、 自らカレントディレクトリを変更したり、 ファイルにアクセスしたりすべきではない、という点に注意すること。 .TP .B FTS_NOSTAT .\"O By default, returned .\"O .I FTSENT .\"O structures reference file characteristic information (the .\"O .I statp .\"O field) for each file visited. .\"O This option relaxes that requirement as a performance optimization, .\"O allowing the .\"O fts functions to set the .\"O .I fts_info .\"O field to .\"O .B FTS_NSOK .\"O and leave the contents of the .\"O .I statp .\"O field undefined. デフォルトでは、返された .I FTSENT 構造体は、たどられた各ファイルについてのファイル特徴情報 .I ( statp フィールド) を参照する。 このオプションは、 fts 関数群が .I fts_info フィールドを .B FTS_NSOK に設定し .I statp の内容を定義されないままにすることを許すことにより、 パフォーマンスの最適化に必要なものを緩和する。 .TP .B FTS_PHYSICAL .\"O This option causes the .\"O fts routines to return .\"O .I FTSENT .\"O structures for symbolic links themselves instead .\"O of the target files they point to. .\"O If this option is set, .\"O .I FTSENT .\"O structures for all symbolic links in the .\"O hierarchy are returned to the application. .\"O Either .\"O .B FTS_LOGICAL .\"O or .\"O .B FTS_PHYSICAL .\"O .I must .\"O be provided to the .\"O .BR fts_open () .\"O function. このオプションは、 fts ルーチンにシンボリックリンクが指しているファイルではなく、 シンボリックリンク自身の .I FTSENT 構造体を返させる。 このオプションが設定されると、階層中のすべてのシンボリックリンクの .I FTSENT 構造体がアプリケーションに返される。 .B FTS_LOGICAL または .B FTS_PHYSICAL のどちらかを .BR fts_open () 関数に与えなければ「ならない」。 .TP .B FTS_SEEDOT .\"O By default, unless they are specified as path arguments to .\"O .BR fts_open (), .\"O any files named .\"O "." .\"O or .\"O ".." .\"O encountered in the file hierarchy are ignored. .\"O This option causes the .\"O fts routines to return .\"O .I FTSENT .\"O structures for them. デフォルトでは、 .BR fts_open () のパス引き数として指定されない限り、ファイル階層中にある "." または ".." という名前のファイルは無視される。 このオプションは、 fts ルーチンにこれらのファイルの .I FTSENT 構造体を返させる。 .TP .B FTS_XDEV .\"O This option prevents .\"O fts from descending into directories that have a different device number .\"O than the file from which the descent began. このオプションは、 fts が下り始めのファイルとは異なるデバイス番号を持っている ディレクトリに下りるのを阻止する。 .\" .El .PP .\"O The argument .\"O .BR compar () .\"O specifies a user-defined function which may be used to order the traversal .\"O of the hierarchy. .\"O It .\"O takes two pointers to pointers to .\"O .I FTSENT .\"O structures as arguments and .\"O should return a negative value, zero, or a positive value to indicate .\"O if the file referenced by its first argument comes before, in any order .\"O with respect to, or after, the file referenced by its second argument. .\"O The .\"O .IR fts_accpath , .\"O .I fts_path .\"O and .\"O .I fts_pathlen .\"O fields of the .\"O .I FTSENT .\"O structures may .\"O .I never .\"O be used in this comparison. .\"O If the .\"O .I fts_info .\"O field is set to .\"O .B FTS_NS .\"O or .\"O .BR FTS_NSOK , .\"O the .\"O .I fts_statp .\"O field may not either. .\"O If the .\"O .BR compar () .\"O argument is .\"O .BR NULL , .\"O the directory traversal order is in the order listed in .\"O .I path_argv .\"O for the root paths, and in the order listed in the directory for .\"O everything else. 引き数 .BR compar () は、階層をたどる順番を決めるのに使われるユーザー定義関数を指定する。 この関数は、引き数として .I FTSENT 構造体のポインタのポインタを 2 つとり、 1 番目の引き数で参照されているファイルが 2 番目の引き数で参照されているファイルより 前にある場合は負の値・同じ場合はゼロ・後にある場合は正の値を 返さなければならない。 .I FTSENT 構造体の .IR fts_accpath , .IR fts_path , .I fts_pathlen フィールドは、この比較に「絶対」使ってはいけない。 .I fts_info フィールドが .B FTS_NS または .B FTS_NSOK に設定される場合、 .I fts_statp フィールドはこれらのどちらでもない。 .BR compar () 引き数が .B NULL の場合、ディレクトリをたどる順番は、ルートパスについては .I path_argv のなかでリストされた順番で、 その他のファイルについてはディレクトリ内でリストされた順番となる。 .SS fts_read() .\"O The .\"O .BR fts_read () .\"O function returns a pointer to an .\"O .I FTSENT .\"O structure describing a file in .\"O the hierarchy. .\"O Directories (that are readable and do not cause cycles) are visited at .\"O least twice, once in preorder and once in postorder. .\"O All other files are visited at least once. .\"O (Hard links between directories that do not cause cycles or symbolic .\"O links to symbolic links may cause files to be visited more than once, .\"O or directories more than twice.) .BR fts_read () 関数は、階層中のファイルを記述する .I FTSENT 構造体へのポインタを返す。 (読み込み可能で、循環していない) ディレクトリは、 1 回は preorder で、もう 1 回は postorder で、少なくとも 2 回たどられる。 他のファイルは、少なくとも 1 回たどられる。 (ディレクトリ間のハードリンクによって 循環やシンボリックリンクへのシンボリックリンクが起こらない場合、 ファイルは 2 回以上、ディレクトリは 3 回以上たどられる。) .PP .\"O If all the members of the hierarchy have been returned, .\"O .BR fts_read () .\"O returns .\"O .B NULL .\"O and sets the external variable .\"O .I errno .\"O to 0. .\"O If an error unrelated to a file in the hierarchy occurs, .\"O .BR fts_read () .\"O returns .\"O .B NULL .\"O and sets .\"O .I errno .\"O appropriately. .\"O If an error related to a returned file occurs, a pointer to an .\"O .I FTSENT .\"O structure is returned, and .\"O .I errno .\"O may or may not have been set (see .\"O .IR fts_info ). 階層中のすべてのメンバーが返された場合、 .BR fts_read () は .B NULL を返し、外部変数 .I errno を 0 にする。 階層中のファイルに関係しないエラーが起こった場合、 .BR fts_read () は .B NULL を返し、 .I errno をエラーに対応した値にする。 階層中のファイルに関係したエラーが起こった場合、 .I FTSENT 構造体へのポインタが返され、 .I errno は設定される場合と設定されない場合がある .RI ( fts_info を参照すること)。 .PP .\"O The .\"O .I FTSENT .\"O structures returned by .\"O .BR fts_read () .\"O may be overwritten after a call to .\"O .BR fts_close () .\"O on the same file hierarchy stream, or, after a call to .\"O .BR fts_read () .\"O on the same file hierarchy stream unless they represent a file of type .\"O directory, in which case they will not be overwritten until after a call to .\"O .BR fts_read () .\"O after the .\"O .I FTSENT .\"O structure has been returned by the function .\"O .BR fts_read () .\"O in postorder. .BR fts_read () によって返される .I FTSENT 構造体は、同じファイル階層ストリームへの .BR fts_close () の呼出しの後に上書きされる。 また、同じファイル階層ストリームへの .BR fts_read () の呼出しの後でも、構造体がディレクトリを表現していない限り上書きされる。 この場合、 .BR fts_read () 関数によって postorder で .I FTSENT 構造体が返された後、 .BR fts_read () の呼出しがあるまで、 これらの構造体は上書きされない。 .SS fts_children() .\"O The .\"O .BR fts_children () .\"O function returns a pointer to an .\"O .I FTSENT .\"O structure describing the first entry in a NULL-terminated linked list of .\"O the files in the directory represented by the .\"O .I FTSENT .\"O structure most recently returned by .\"O .BR fts_read (). .\"O The list is linked through the .\"O .I fts_link .\"O field of the .\"O .I FTSENT .\"O structure, and is ordered by the user-specified comparison function, if any. .\"O Repeated calls to .\"O .BR fts_children () .\"O will recreate this linked list. .BR fts_children () 関数は、 .I FTSENT 構造体へのポインタを返す。 この構造体は、( .BR fts_read () で最も新しく返された .I FTSENT 構造体で表現されるディレクトリにあるファイルの) NUL 終端されたリンクリストの最初のエントリを記述する。 このリストは、 .I FTSENT 構造体の .I fts_link フィールドを使ってリンクされ、 ユーザー指定の比較関数がある場合は、それで順序づけられる。 .BR fts_children () の呼出しを繰り返すことで、 このリンクリストは再生成される。 .PP .\"O As a special case, if .\"O .BR fts_read () .\"O has not yet been called for a hierarchy, .\"O .BR fts_children () .\"O will return a pointer to the files in the logical directory specified to .\"O .BR fts_open (), .\"O that is, the arguments specified to .\"O .BR fts_open (). .\"O Otherwise, if the .\"O .I FTSENT .\"O structure most recently returned by .\"O .BR fts_read () .\"O is not a directory being visited in preorder, .\"O or the directory does not contain any files, .\"O .BR fts_children () .\"O returns .\"O .B NULL .\"O and sets .\"O .I errno .\"O to zero. .\"O If an error occurs, .\"O .BR fts_children () .\"O returns .\"O .B NULL .\"O and sets .\"O .I errno .\"O appropriately. 特別な場合として、 .BR fts_read () がファイル階層について呼ばれていない場合、 .BR fts_children () は .BR fts_open () に指定された論理ディレクトリ (つまり、 .BR fts_open () に指定された引き数) の中にあるファイルへのポインタを返す。 それ以外の場合で、 .BR fts_read () によって最も新しく返された .I FTSENT 構造体が preorder でたどられたディレクトリでない場合や 何も含んでいないディレクトリの場合は、 .BR fts_children () は .B NULL を返し、 .I errno を 0 にする。 エラーが起こった場合、 .BR fts_children () は .B NULL を返し、 .I errno をエラーに対応した値にする。 .PP .\"O The .\"O .I FTSENT .\"O structures returned by .\"O .BR fts_children () .\"O may be overwritten after a call to .\"O .BR fts_children (), .\"O .BR fts_close () .\"O or .\"O .BR fts_read () .\"O on the same file hierarchy stream. .BR fts_children () によって返される .I FTSENT 構造体は、同じファイル階層ストリームへの .BR fts_children (), .BR fts_close (), .BR fts_read () の呼出しの後に上書きされる場合がある。 .PP .\"O .I Option .\"O may be set to the following value: .I option は、次の値に設定できる。 .\" .Bl -tag -width FTS_NAMEONLY .TP .B FTS_NAMEONLY .\"O Only the names of the files are needed. .\"O The contents of all the fields in the returned linked list of structures .\"O are undefined with the exception of the .\"O .I fts_name .\"O and .\"O .I fts_namelen .\"O fields. ファイル名のみが必要とされている。 返された構造体のリンクリストの .IR fts_name , .I fts_namelen フィールド以外の すべてのフィールドの内容は定義されない。 .\" .El .SS fts_set() .\"O The function .\"O .BR fts_set () .\"O allows the user application to determine further processing for the .\"O file .\"O .I f .\"O of the stream .\"O .IR ftsp . .\"O The .\"O .BR fts_set () .\"O function .\"O returns 0 on success, and \-1 if an error occurs. .\"O .I Option .\"O must be set to one of the following values: 関数 .BR fts_set () は、ユーザーアプリケーションが ストリーム .I ftsp のファイル .I f について更なる処理を決定すること許す。 .BR fts_set () 関数は、成功した場合は 0 を、エラーが起こった場合は \-1 を返す。 .I option は、次の値のいずれか 1 つに設定されなければならない。 .\" .Bl -tag -width FTS_PHYSICAL .TP .B FTS_AGAIN .\"O Re-visit the file; any file type may be revisited. .\"O The next call to .\"O .BR fts_read () .\"O will return the referenced file. .\"O The .\"O .I fts_stat .\"O and .\"O .I fts_info .\"O fields of the structure will be reinitialized at that time, .\"O but no other fields will have been changed. .\"O This option is meaningful only for the most recently returned .\"O file from .\"O .BR fts_read (). .\"O Normal use is for postorder directory visits, where it causes the .\"O directory to be revisited (in both preorder and postorder) as well as all .\"O of its descendants. ファイルを再びたどる。すべてのファイルタイプが再びたどられる。 次の .BR fts_read () の呼出しにより、参照されているファイルが返される。 構造体の .IR fts_stat , .I fts_info フィールドはこの時に初期化されるが、他のフィールドは変更されない。 このオプションは、 .BR fts_read () によって最も新しく返されたファイルについてのみ意味を持つ。 通常は、postorder でディレクトリをたどる場合に使用し、 その下の階層と同様に、 ディレクトリを (preorder と postorder の両方で) 再びたどらせる。 .TP .B FTS_FOLLOW .\"O The referenced file must be a symbolic link. .\"O If the referenced file is the one most recently returned by .\"O .BR fts_read (), .\"O the next call to .\"O .BR fts_read () .\"O returns the file with the .\"O .I fts_info .\"O and .\"O .I fts_statp .\"O fields reinitialized to reflect the target of the symbolic link instead .\"O of the symbolic link itself. .\"O If the file is one of those most recently returned by .\"O .BR fts_children (), .\"O the .\"O .I fts_info .\"O and .\"O .I fts_statp .\"O fields of the structure, when returned by .\"O .BR fts_read (), .\"O will reflect the target of the symbolic link instead of the symbolic link .\"O itself. .\"O In either case, if the target of the symbolic link does not exist the .\"O fields of the returned structure will be unchanged and the .\"O .I fts_info .\"O field will be set to .\"O .BR FTS_SLNONE . .\"O .PP .\"O If the target of the link is a directory, the preorder return, followed .\"O by the return of all of its descendants, followed by a postorder return, .\"O is done. 参照されてるファイルは、シンボリックリンクでなければならない。 参照されているファイルが .BR fts_read () によって最も新しく返されたものである場合、次の .BR fts_read () の呼出しでは、シンボリックリンクそのものではなく、 シンボリックリンクが指している先を反映するように .IR fts_info , .I fts_statp を再び初期化したファイルが返される。 ファイルが .BR fts_children () によって最も新しく返されたものの 1 つである場合、 .BR fts_read () によって返されたとき、構造体の .IR fts_info , .I fts_statp フィールドは、シンボリックリンクそのものではなく、 シンボリックリンクが指している先を反映する。 どちらの場合でも、シンボリックリンクが指している先がないときは、 返された構造体のフィールドは変更されず、 .I fts_info フィールドが .B FTS_SLNONE に設定される。 .PP .\"O If the target of the link is a directory, the preorder return, followed .\"O by the return of all of its descendants, followed by a postorder return, .\"O is done. リンク先がディレクトリの場合、 ファイルが preorder で返された後、下の階層のすべてファイルが返され、 その後で postorder で返される。 .TP .B FTS_SKIP .\"O No descendants of this file are visited. .\"O The file may be one of those most recently returned by either .\"O .BR fts_children () .\"O or .\"O .BR fts_read (). このファイルの下の階層はたどられない。 このファイルは、 .BR fts_children () または .BR fts_read () のどちらかによって最も新しく返されたものの 1 つである。 .\" .El .SS fts_close() .\"O The .\"O .BR fts_close () .\"O function closes a file hierarchy stream .\"O .I ftsp .\"O and restores the current directory to the directory from which .\"O .BR fts_open () .\"O was called to open .\"O .IR ftsp . .\"O The .\"O .BR fts_close () .\"O function .\"O returns 0 on success, and \-1 if an error occurs. .BR fts_close () 関数は、ファイル階層ストリーム .I ftsp を閉じる。そして、現在のディレクトリを .I ftsp を開くために .BR fts_open () が呼ばれたディレクトリに復元する。 .BR fts_close () 関数は、成功した場合は 0 を、エラーが起こった場合は \-1 を返す。 .\"O .SS ERRORS .SS エラー .\"O The function .\"O .BR fts_open () .\"O may fail and set .\"O .I errno .\"O for any of the errors specified for the library functions .\"O .BR open (2) .\"O and .\"O .BR malloc (3). 関数 .BR fts_open () が失敗した場合、 .I errno は、ライブラリ関数 .BR open (2) と .BR malloc (3) に対して指定されるエラーに設定される。 .PP .\"O The function .\"O .BR fts_close () .\"O may fail and set .\"O .I errno .\"O for any of the errors specified for the library functions .\"O .BR chdir (2) .\"O and .\"O .BR close (2). 関数 .BR fts_close () が失敗した場合、 .I errno は、ライブラリ関数 .BR chdir (2) と .BR close (2) に対して指定されるエラーに設定される。 .PP .\"O The functions .\"O .BR fts_read () .\"O and .\"O .BR fts_children () .\"O may fail and set .\"O .I errno .\"O for any of the errors specified for the library functions .\"O .BR chdir (2), .\"O .BR malloc (3), .\"O .BR opendir (3), .\"O .BR readdir (3) .\"O and .\"O .BR stat (2). 関数 .BR fts_read () と .BR fts_children () が失敗した場合、 .I errno は、ライブラリ関数 .BR chdir (2), .BR malloc (3), .BR opendir (3), .BR readdir (3), .BR stat (2) に対して指定されるエラーに設定される。 .PP .\"O In addition, .\"O .BR fts_children (), .\"O .BR fts_open () .\"O and .\"O .BR fts_set () .\"O may fail and set .\"O .I errno .\"O as follows: 更に、 .BR fts_children (), .BR fts_open (), .BR fts_set () が失敗した場合、 .I errno が次の値にされる。 .TP .B EINVAL .\"O The options were invalid. オプションが無効であった。 .\"O .SH VERSIONS .SH バージョン .\"O These functions are available in Linux since glibc2. これらの関数は、Linux では glibc2 から使用可能である。 .\"O SH "CONFORMING TO" .SH 準拠 4.4BSD. .\" The following statement is years old, and seems no closer to .\" being true -- mtk .\"O .\" The .\"O .\" .I fts .\"O .\" utility is expected to be included in a future .\"O .\" POSIX.1 .\"O .\" revision. .\" .I fts .\" ユーティリティは、将来の .\" POSIX.1 .\" リビジョンに含まれると期待されている。 .\"O .SH SEE ALSO .SH 関連項目 .BR find (1), .BR chdir (2), .BR stat (2), .BR ftw (3), .BR qsort (3)