
2

3

4

5



6

7

8

9

10

11

12



13

14

15

16

在程序中獲得普通文件,目錄,管道,socket,字符,塊()的屬性。
函數原型
#include <sys/stat.h>
int stat(const char *restrict pathname, struct stat *restrict buf);
提供文件名字,獲取文件對應屬性。把相應的屬性存放到 buf中。
2 文件對應的屬性
struct stat {
mode_t st_mode; //文件對應的模式,文件,目錄等
ino_t st_ino; //inode節點號
dev_t st_dev; //設備號碼
dev_t st_rdev; //特殊設備號碼
nlink_t st_nlink; //文件的連接數
uid_t st_uid; //文件所有者
gid_t st_gid; //文件所有者對應的組
off_t st_size; //普通文件,對應的文件字節數
time_t st_atime; //文件最后被訪問的時間
time_t st_mtime; //文件內容最后被修改的時間
time_t st_ctime; //文件狀態改變時間
blksize_t st_blksize; //文件內容對應的塊大小
blkcnt_t st_blocks; //文件內容對應的塊數量
};
可以通過上面提供的函數,返回一個結構體,保存著文件的信息。
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/fxpbupt/archive/2008/11/17/3313427.aspx