[英]nftw passing tflag with undefined value
While traversing a directory using nftw like so, 像这样使用nftw遍历目录时,
nftw((argc < 2) ? "." : argv[1], rm, 20, FTW_DEPTH|FTW_PHYS)
nftw is passing a value of 5 to the rm function's tflag parameter when it encounters a directory. 当nftw遇到目录时,它将向rm函数的tflag参数传递5值。 The ftw.h header only specifies an enum with 4 values (0-3) for the tflag parameter, of which FTW_D or 1 is the appropriate value for a directory.
ftw.h标头仅为tflag参数指定一个包含4个值(0-3)的枚举,其中FTW_D或1是目录的适当值。 The fpath value appears to be correct in all instances.
在所有情况下,fpath值似乎都是正确的。
So my question is this. 所以我的问题是这个。 Why is it passing 5 and not 1 for the tflag, and what does 5 mean for the tflag?
为什么tflag传递5而不是1,tflag 5代表什么?
EDIT: 编辑:
The value was in fact FTW_DP (Directory, all subdirs have been visited) which was defined below in an environment dependent portion which I failed to notice. 该值实际上是FTW_DP(目录,所有子目录均已被访问),该值在以下我未注意到的环境相关部分中定义。
The POSIX specification of nftw()
says that the flag argument to your rm
function shall be one of: nftw()
的POSIX规范指出,您的rm
函数的flag参数应为以下之一:
FTW_D
The object is a directory.FTW_D
对象是目录。FTW_DNR
The object is a directory that cannot be read.FTW_DNR
对象是无法读取的目录。 The fn function shall not be called for any of its descendants.fn函数的任何后代均不得调用。
FTW_DP
The object is a directory and subdirectories have been visited.FTW_DP
该对象是目录,已经访问了子目录。 (This condition shall only occur if the FTW_DEPTH flag is included in flags.)(只有在标志中包含FTW_DEPTH标志时,才会发生此情况。)
FTW_F
The object is a non-directory file.FTW_F
该对象是一个非目录文件。FTW_NS
The stat() function failed on the object because of lack of appropriate permission.FTW_NS
由于缺少适当的权限,此对象的stat()函数失败。 The stat buffer passed to fn is undefined.传递给fn的状态缓冲区未定义。 Failure of stat() for any other reason is considered an error and nftw() shall return -1.
由于其他任何原因导致的stat()失败均被视为错误,并且nftw()应返回-1。
FTW_SL
The object is a symbolic link.FTW_SL
该对象是符号链接。 (This condition shall only occur if the FTW_PHYS flag is included in flags.)(仅当FTW_PHYS标志包含在标志中时,此条件才会发生。)
FTW_SLN
The object is a symbolic link that does not name an existing file.FTW_SLN
该对象是不命名现有文件的符号链接。 (This condition shall only occur if the FTW_PHYS flag is not included in flags.)(仅当FTW_PHYS标志未包含在标志中时,此条件才会发生。)
Since you don't identify your system and the standard doesn't define what number shall be associated with the flag argument to the called function, no-one can identify what the 5
means on your system. 由于您没有标识系统,而标准也没有定义与被调用函数的flag参数关联的数字,因此没有人可以识别
5
在系统上的含义。 However, there are enough options that 5
doesn't seem implausible as a value. 但是,有足够多的选择使
5
看起来不令人难以置信。
On Mac OS X (10.9.5), the value 5
would be FTW_SL
. 在Mac OS X(10.9.5)上,值
5
将为FTW_SL
。 On another system, based on OSF, jedwards notes in a comment that the value 5
is for FTW_DP
, thus fully justifying my observation that the flag represented by 5
is system-dependent. 在基于OSF的另一个系统上, jedwards在注释中指出值
5
表示FTW_DP
,因此完全证明了我的观察力: 5
表示的标志与系统有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.