Members of Dirent structure

不打扰是莪最后的温柔 提交于 2019-12-17 18:04:42

问题


I have started working with dirent.h library and I came across a very useful member of "struct dirent" structer which struct dirent *p->d_name in my book. But unfortunatly it doesn't states any other members of this structure;

I was wondering what else are the members of this structure and what are they used for?

Regards


回答1:


The structure, struct dirent refers to directory entry.

http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html

In linux it is defined as:

struct dirent {
    ino_t          d_ino;       /* inode number */
    off_t          d_off;       /* offset to the next dirent */
    unsigned short d_reclen;    /* length of this record */
    unsigned char  d_type;      /* type of file; not supported
                                   by all file system types */
    char           d_name[256]; /* filename */
};

refer: man readdir

Or just look for "dirent.h" in the include directory.




回答2:


There are only two members (from wikipedia):

  • ino_t d_ino - file serial number
  • char d_name[] - name of entry (will not exceed a size of NAME_MAX)

Take a look at the unix spec as well.




回答3:


in addition to above answer of @Binyamin Sharet:

 off_t d_off - file offset
    unsigned short int d_reclen - length of the dirent record
    unsigned short int d_namlen - length of name
    unsigned int d_type - type of file


来源:https://stackoverflow.com/questions/12991334/members-of-dirent-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!