在linux中,当stat()与断开的链接文件一起使用时,它会失败-1.所以我用了lstat()哪个成功了.
对于Windows中的相同情况,_stat()失败的快捷方式失败,但_lstat()在Windows中没有.请帮助lstat()在Windows中找到替代方案.
GetFileAttributes或GetFileAttributesEx可能(如果我理解stat并且lstat正确).引用文档:
符号链接行为 - 如果路径指向符号链接,则该函数返回符号链接的属性.
接受的答案没有提供完整的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 */
};
Run Code Online (Sandbox Code Playgroud)
但GetFileAttributes..不提供任何所有者信息(它返回WIN32_FIND_DATA对象中的数据).如果您需要该所有者信息,则看起来您可以使用GetSecurityInfo[1].
[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa446629%28v=vs.85%29.aspx