是否可以使用struct stat描述符获取和设置文件名?

ana*_*kos 5 c unix

是否可以在获取或设置(重命名)文件名时提供文件的绝对路径,并以struct stat实例作为lstat函数的参数?正如我在文档中发现struct那样;

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 */
};
Run Code Online (Sandbox Code Playgroud)

我想要的是这样的东西;

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
Run Code Online (Sandbox Code Playgroud)

wno*_*ise 3

不。在 unix 中,名称不是文件的固有属性。一个文件可以有多个名称(请参阅硬链接),甚至可以没有。

名称只是目录中的条目。