是否可以使用 struct stat 描述符获取和设置文件名? [英] Is it possible getting and setting file name with struct stat descriptor?
本文介绍了是否可以使用 struct stat 描述符获取和设置文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在获取或设置(重命名)文件名时提供文件的绝对路径,以及一个 struct stat 实例作为 lstat 函数的参数.正如我在文档结构中发现的那样;
Is it possible at get or set ( rename ) a file name with giving the absolute path of file, and a struct stat instance as parameters to lstat function. As I find in documentation struct seems like that;
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 */
};
我想要的是这样的;
What I want is something like that;
struct stat *s;
char *path; // assigning the ablosute path of file
int res = lstat(path, s);
if(res == -1)
return errno;
char *name = s->(someFielAboutFileName);
or
s->(someFieldAboutFileName) = name; // setting name
推荐答案
没有.在 unix 中,名称不是文件的固有属性.一个文件可以有多个名称(参见硬链接),甚至没有.
No. In unix, the name is not an inherent property of the file. A file can have multiple names (see hard links) or even none.
名称只是目录中的条目.
The names are just entries in directories.
这篇关于是否可以使用 struct stat 描述符获取和设置文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文