Chinaunix首页 | 论坛 | 博客
  • 博客访问: 199312
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 385
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-16 18:53
个人简介

只要心够决,没有什么不可以!!!

文章存档

2013年(35)

我的朋友

分类: 嵌入式

2013-05-20 19:57:31

mode_t等系统数据类型

mode_t 数据类型究竟是什么类型

让我们逐步查找一下。

首先从文件 /usr/include/sys/stat.h 中找到 mode_t 类型

/usr/include/sys/stat.h -> typedef __mode_t mode_t;

说明 mode_t 只是对 __mode_t 的一种定义。

然后从 /usr/include/bits/types.h 中找到 __mode_t 类型

/usr/include/bits/types.h -> __STD_TYPE __MODE_T_TYPE __mode_t;

说明 __mode_t 也只是对 __MODE_T_TYPE 的一种定义。

/usr/include/bits/typesizes.h -> #define __MODE_T_TYPE __U32_TYPE

说明 __MODE_T_TYPE 是对 __U32_TYPE 的一种定义。

/usr/include/bits/types.h -> #define __U32_TYPE unsigned int

最后 __U32_TYPE 是一种无符号的整数的定义。

从上述推导可以看出,mode_t 实际上也就是一种无符号整数。

另外如下结构 struct stat 定义中的 st_mode 成员变量也是使用的 mode_t 类型的变量。

从 man 2 stat 中可以找到结构 struct stat 的定义,如下:

  struct stat { 
    dev_t   st_dev;   /* ID of device containing file */ 
    ino_t   st_ino;   /* inode number */ 
    mode_t  st_mode;  /* protection */ 
    nlink_t   st_nlink;   /* number of hard links */ 
    uid_t   st_uid;   /* user ID of owner */ 
    gid_t   st_gid;   /* group ID of owner */ 
    dev_t   st_rdev;  /* device ID (if special file) */ 
    off_t   st_size;  /* total size, in bytes */ 
    blksize_t st_blksize; /* blocksize for filesystem I/O */ 
    blkcnt_t  st_blocks;  /* number of blocks allocated */ 
    time_t  st_atime;   /* time of last access */ 
    time_t  st_mtime;   /* time of last modification */ 
    time_t  st_ctime;   /* time of last status change */ 

};

阅读(3751) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~