《C 程序设计语言》第八章 fsize 读取文件夹内容的讨论
发布时间
阅读量:
阅读量
学习"C程序设计语言"第8章有一个案例,在 UNIX 系统中实施文件夹内容的读取以及其他相关操作。
在程序设计中,readdir函数采用了open和read函数以获取文件夹内容。然而,在CentOS 7环境下我始终遇到问题。
查看stackoverflow上有类似的讨论
http://stackoverflow.com/questions/21405048/linux-open-directory-as-a-file
该作者进行了此实验。open能够打开文件夹但无法使用read函数调用,该操作通常会返回-1
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char* argv[]) {
int fd = -1;
if (argc!=1) fd=open(argv[1],O_RDONLY,0);
else fd=open(".",O_RDONLY,0);
if (fd < 0){
perror("file open");
printf("error on open = %d",
全部评论 (0)
还没有任何评论哟~
