我无法识别stat引发的错误.以下程序读取目录中的所有文件并打印文件名:
DIR *dp; struct dirent *dirp; struct stat sb; if((dp = opendir(argv[1]))==NULL) { perror("can't open dir"); } while((dirp = readdir(dp))!=NULL) { if (stat(dirp->d_name,&sb) == -1) { perror("stat"); } printf("File name: %s \n",dirp->d_name); }
样本输出:
/home/eipe stat error: No such file or directory File name: copyofsample File name: a.out File name: . stat error: No such file or directory File name: udpclient.c File name: .. stat error: No such file or directory File name: client.c stat error: No such file or directory File name: ftpclient.c
以下是内容:
ls -l /home/eipe/c -rwxr-xr-x 1 eipe egroup 7751 2011-02-24 15:18 a.out -rw-r--r-- 1 eipe egroup 798 2011-02-24 13:50 client.c -rw-r--r-- 1 eipe egroup 15 2011-02-24 15:34 copyofsample -rw-r--r-- 1 eipe egroup 1795 2011-02-24 15:33 ftpclient.c -rw-r--r-- 1 eipe egroup 929 2011-02-24 13:34 udpclient.c