前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >dirent相关 转

dirent相关 转

作者头像
domain0
发布2018-08-02 11:25:25
2930
发布2018-08-02 11:25:25
举报
文章被收录于专栏:运维一切运维一切

主要包括两个文件:/usr/include/dirent.h  和/usr/include/bits/dirent.h

struct dirent   { #ifndef __USE_FILE_OFFSET64     __ino_t d_ino;     __off_t d_off; #else     __ino64_t d_ino;     __off64_t d_off; #endif     unsigned short int d_reclen;     unsigned char d_type;     char d_name[256];       /* We must not include limits.h! */   }; 

相关文件类型说明:

enum   {     DT_UNKNOWN = 0, # define DT_UNKNOWN DT_UNKNOWN     DT_FIFO = 1, # define DT_FIFO    DT_FIFO     DT_CHR = 2, # define DT_CHR     DT_CHR     DT_DIR = 4, # define DT_DIR     DT_DIR     DT_BLK = 6, # define DT_BLK     DT_BLK     DT_REG = 8, # define DT_REG     DT_REG     DT_LNK = 10,  # define DT_LNK     DT_LNK     DT_SOCK = 12,  # define DT_SOCK    DT_SOCK     DT_WHT = 14 # define DT_WHT     DT_WHT   }; 

其中有一些type我知道,但是一些我还不了解,在实际中,d_name老是不显示出来,不知道是什么原因:

测试程序:

#include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <sys/stat.h> #include <errno.h> void printdir(char *dir, int depth) { struct dirent *entry; DIR *dp; struct stat statbuf; dp = opendir(dir); if (dp == NULL) { perror("opendir error"); } // chdir(dp); entry = readdir(dp); printf("%d,  %d,   %s\n", entry->d_reclen, entry->d_type, entry->d_name); } int main(int argc, char* argv[]) { char *dir = "."; if (argc == 2) { dir = argv[1]; printdir(dir, 0); } return 0; }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016/05/22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档