readdir(3)返回的文件顺序,与struct dirent中d_off的值相关,和inode号的大小没有关系。
#include <sys/types.h> #include <dirent.h> #include <stdio.h>
int main() { DIR *dirp; struct dirent *dp;
dirp = opendir("."); while (dp = readdir(dirp)) { printf("%s: \toff=%011d\n", dp->d_name, dp->d_off); }
return 0; }
// struct dirent // { // long d_ino; /* inode number */ // off_t d_off; /* offset to this dirent */ // unsigned short d_reclen; /* length of this d_name */ // char d_name [NAME_MAX+1]; /* filename (null-terminated) */ // }
/* # ./readdir file2: off=00581882856 .: off=01047962852 file3: off=01376021557 dir2: off=01431881775 dir1: off=01558077073 file1: off=01576748262 ..: off=02147483647 */
|
阅读(745) | 评论(0) | 转发(0) |