linux提供了stat函数,可以通过它获得文件的详细信息:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int stat(const char *pathname, struct stat *statbuf);
参数说明:
pathname:文件的路径
statbuf:用于保存文件信息的结构
返回值:
0:成功
-1:失败,errno会设置具体的错误值
以下是struct stat结构体的说明:
struct stat {
dev_t st_dev; /* ID of device containing file */文件使用的设备号
ino_t st_ino; /* Inode number */ 索引节点号
mode_t st_mode; /* File type and mode */文件类型和模式
nlink_t st_nlink; /* Number of hard links */文件的硬连接数
uid_t st_uid; /* User ID of owner */所有者的用户ID
gid_t st_gid;