我在软呢帽上试过这个密码,但是
No such file or directory
和
Permission denied
错误。
如何处理错误并继续扫描文件系统?
ftw()从路径开始
/
#define _XOPEN_SOURCE 500
#include
#include
#include
FILE * output;
static int display_info(const char * fpath, const struct stat * st, int tflag)
{
switch(tflag){
case FTW_F://ok, file
break;
case FTW_D://ok, directory
break;
case FTW_SL://symlink
return -1;
case FTW_NS://stat failed
return -1;
case FTW_DNR://read failed
return -1;
}
fprintf(output, fpath);
fprintf(output, "\n");
return 0;
}
int main(int argc, char * argv[])
{
time_t t0;
time(&t0);
output = fopen("/home/sad/output.txt", "w");
if(argc < 2){
printf("Usage: %s [path]\n", argv[0]);
return -1;
}
if(ftw(argv[1], display_info, 99) == -1){
perror("???ftw()");
return -1;
}
fclose(output);
time_t t1;
time(&t1);
printf("%.3f seconds\n", difftime(t1, t0));
return 0;
}