Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is lstat() alternative in windows?

Tags:

c

stat

In linux, when stat() is used with broken link files, it fails with -1. So I used lstat() which succeeded.

For the same case in windows, _stat() fails with broken shortcuts, but there is no _lstat() in windows. Please help to find the alternative for lstat() in windows.

like image 257
Gautham Polisetty Avatar asked Aug 23 '12 06:08

Gautham Polisetty


2 Answers

The accepted answer does not provide a full stat equivalent. The stat struct is defined as

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

but GetFileAttributes.. does not provide any owner information (it returns data in a WIN32_FIND_DATA object). If you need that owner information, it looks like you can use GetSecurityInfo [1].

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

like image 71
user877329 Avatar answered Sep 23 '22 13:09

user877329


GetFileAttributes or GetFileAttributesEx probably (if I understood stat and lstat right). Quoting from the docs:

Symbolic link behavior—If the path points to a symbolic link, the function returns attributes for the symbolic link.

like image 31
Joey Avatar answered Sep 24 '22 13:09

Joey