While traversing a directory using nftw like so,
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. 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. The fpath value appears to be correct in all instances.
So my question is this. Why is it passing 5 and not 1 for the tflag, and what does 5 mean for the tflag?
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.
The POSIX specification of nftw()
says that the flag argument to your rm
function shall be one of:
FTW_D
The object is a directory.FTW_DNR
The object is a directory that cannot be read. The fn function shall not be called for any of its descendants.FTW_DP
The object is a directory and subdirectories have been visited. (This condition shall only occur if the FTW_DEPTH flag is included in flags.)FTW_F
The object is a non-directory file.FTW_NS
The stat() function failed on the object because of lack of appropriate permission. The stat buffer passed to fn is undefined. Failure of stat() for any other reason is considered an error and nftw() shall return -1.FTW_SL
The object is a symbolic link. (This condition shall only occur if the FTW_PHYS flag is included in flags.)FTW_SLN
The object is a symbolic link that does not name an existing file. (This condition shall only occur if the FTW_PHYS flag is not included in flags.)
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. However, there are enough options that 5
doesn't seem implausible as a value.
On Mac OS X (10.9.5), the value 5
would be 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.