访问和显示文件元数据
在文件操作中,了解和显示文件的元数据是非常重要的。元数据包含了文件的各种信息,如所有者、修改时间等。下面将详细介绍如何访问和显示这些文件元数据。
1. 获取文件元数据的系统调用
有三种标准化的系统调用可以用来获取文件的 i - node 信息,分别是 stat 、 fstat 和 lstat ,同时还有一个广为人知的命令 ls 。
-
stat:通过路径获取文件信息
#include <sys/stat.h>
int stat(
const char *path,
/* pathname */
struct stat *buf
/* returned information */
);
/* Returns 0 on success or -1 on error (sets errno) */
-
lstat:通过路径获取文件信息,但不跟随符号链接
#include <sys/stat.h>
int lstat(
const char *path,
/* pathname */
struct stat *buf
/* returned information */
);
/* Returns 0 on success or -1
超级会员免费看
订阅专栏 解锁全文
3543

被折叠的 条评论
为什么被折叠?



