3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/crtdll/sys/fstat.c
6 * PURPOSE: Gather file information
7 * PROGRAMER: Boudewijn Dekker
13 #include <msvcrt/sys/types.h>
14 #include <msvcrt/sys/stat.h>
15 #include <msvcrt/fcntl.h>
16 #include <msvcrt/string.h>
17 #include <msvcrt/errno.h>
18 #include <msvcrt/internal/file.h>
24 int _fstat(int fd
, struct stat
* statbuf
)
26 BY_HANDLE_FILE_INFORMATION FileInformation
;
33 if (!GetFileInformationByHandle(_get_osfhandle(fd
),&FileInformation
)) {
37 statbuf
->st_ctime
= FileTimeToUnixTime(&FileInformation
.ftCreationTime
,NULL
);
38 statbuf
->st_atime
= FileTimeToUnixTime(&FileInformation
.ftLastAccessTime
,NULL
);
39 statbuf
->st_mtime
= FileTimeToUnixTime(&FileInformation
.ftLastWriteTime
,NULL
);
40 if (statbuf
->st_atime
==0)
41 statbuf
->st_atime
= statbuf
->st_mtime
;
42 if (statbuf
->st_ctime
==0)
43 statbuf
->st_ctime
= statbuf
->st_mtime
;
45 statbuf
->st_dev
= FileInformation
.dwVolumeSerialNumber
;
46 statbuf
->st_size
= FileInformation
.nFileSizeLow
;
47 statbuf
->st_nlink
= FileInformation
.nNumberOfLinks
;
48 statbuf
->st_mode
= S_IREAD
;
49 if (FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
50 statbuf
->st_mode
|= S_IFDIR
| S_IEXEC
;
52 statbuf
->st_mode
|= S_IFREG
;
53 if (!(FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
))
54 statbuf
->st_mode
|= S_IWRITE
;