课本上的一道题目
- C/C++ code
...../* dirname = *++argv*/fd = open(dirname, O_RDONLY, 0).....struct direct { ino_t d_ino; char d_name[DIRSIZ];};.....struct direct dirbuf;.....while (read(dp->fd, (char *) &dirbuf, sizeof(dirbuf)) == sizeof(dirbuf)).....这是《The C programming Language》8-6的一段代码
按照作者的思想是当输入为目录时read读取每个目录项,并储存
但是当输入的是目录时read输出的都是 -1
希望指点下 是哪里出现错误了
[解决办法]
On error, -1 is returned, and errno is set appropriately.
In this case it is left unspecified whether the file position (if any) changes.
可以用strerror(errno)查看哪儿出了问题
[解决办法]
- C/C++ code
/* dirname = *++argv*/
[解决办法]
貌似read不能读目录的
[解决办法]