文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>struct dirent中的d_name的长度问题

struct dirent中的d_name的长度问题

时间:2009-03-26  来源:typhoon85

  在看有关目录操作的问题时,为什么在AIX中的dirent.h中定义的 struct dirent,数组d_name[255]的长度是255,而在sun下面确是d_name[1]
 
我从linux的/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! */
  };

#ifdef __USE_LARGEFILE64
struct dirent64
  {
    __ino64_t d_ino;
    __off64_t d_off;
    unsigned short int d_reclen;
    unsigned char d_type;
    char d_name[256];           /* We must not include limits.h! */
  };
#endif

我在AIX 下看到的定义如下:

#define _D_NAME_MAX 255

struct  dirent {
        __ulong64_t     d_offset;       /* real off after this entry */
        ino_t           d_ino;          /* inode number of entry */
        ushort_t        d_reclen;       /* length of this record */
        ushort_t        d_namlen;       /* length of string in d_name */
        char            d_name[_D_NAME_MAX+1];  /* name must be no longer than t
                                        /* redefine w/#define when name decided
};

而在sunOS下面看到的是

typedef struct dirent {
        ino_t           d_ino;          /* "inode number" of entry */
        off_t           d_off;          /* offset of disk directory entry */
        unsigned short  d_reclen;       /* length of this record */
        char            d_name[1];      /* name of file */
} dirent_t;

2008-2-28 19:46cugb_cat
man readdir
       On Linux, the dirent structure is defined as follows:

          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 */
              char           d_name[256]; /* filename */
          };
排行榜 更多 +
日更计划漫画

日更计划漫画

浏览阅读 下载
浮生忆玲珑

浮生忆玲珑

角色扮演 下载
摩托追击

摩托追击

赛车竞速 下载