Linux では、stat()
壊れたリンク ファイルで を使用すると、 で失敗し-1
ます。だから私はlstat()
成功したものを使いました。
Windows の同じケースでは_stat()
、壊れたショートカットで失敗しますが_lstat()
、Windows にはありません。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
おそらくGetFileAttributesまたはGetFileAttributesEx(私が理解stat
して正しければlstat
)。ドキュメントからの引用:
シンボリック リンクの動作 - パスがシンボリック リンクを指している場合、関数はシンボリック リンクの属性を返します。
hey _stat() または stat() は、壊れたショートカットでも問題なく動作します。そのため、Windows には lstat(UNIX) のような代替手段はありません。
Unix では stat() がリンク切れで失敗するため、問題を修正するために lstat が提供されています。
ご協力ありがとうございました。