gpt4 book ai didi

c - Windows 中的 lstat() 替代方法是什么?

转载 作者:太空狗 更新时间:2023-10-29 17:06:21 31 4
gpt4 key购买 nike

在 Linux 中,当 stat() 用于损坏的链接文件时,它会失败并返回 -1。所以我使用了成功的 lstat()

对于 Windows 中的相同情况,_stat() 因快捷方式损坏而失败,但 Windows 中没有 _lstat()。请帮助找到 lstat() 在 windows 中的替代方法。

最佳答案

接受的答案不提供完整的 stat 等价物。 stat 结构定义为

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 512B 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 */
};

但是 GetFileAttributes.. 不提供任何所有者信息(它在 WIN32_FIND_DATA 对象中返回数据)。如果您需要所有者信息,您可以使用 GetSecurityInfo [1]。

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa446629%28v=vs.85%29.aspx

关于c - Windows 中的 lstat() 替代方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12085761/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com