Linux 下有如下API 可以用来获取文件相关信息,譬如文件大小,修改时间等;
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int stat(const char *pathname, struct stat *buf);
int fstat(int fd, struct stat *buf);
int lstat(const char *pathname, struct stat *buf);
//struct stat 结构体
struct stat {
dev_t st_dev; /* ID of device containing file */ 文件ID
ino_t st_ino; /* inode number */ 文件节点
mode_t st_mode; /* protection */ 文件的模式
nink_t st_nlink; /* number of hard links */ 文件的硬链接数
uid_t st_uid; /* user ID of owner */ 文件所有者ID
gid_t st_gid; /* group ID of owner */ 文件的组ID
dev_t st_rdev; /* device ID (if special file) */ 文件的设备ID
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /