3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/msvcrt/sys/fstat.c
6 * PURPOSE: Gather file information
7 * PROGRAMER: Boudewijn Dekker
13 #include <sys/types.h>
18 #include <internal/file.h>
24 int _fstat(int fd
, struct _stat
* statbuf
)
26 BY_HANDLE_FILE_INFORMATION FileInformation
;
35 if ((void*)-1 == (handle
= (void*)_get_osfhandle(fd
)))
43 memset (statbuf
, 0, sizeof(struct stat
));
45 dwFileType
= GetFileType(handle
);
47 if (dwFileType
== FILE_TYPE_DISK
)
49 if (!GetFileInformationByHandle(handle
,&FileInformation
))
54 statbuf
->st_ctime
= FileTimeToUnixTime(&FileInformation
.ftCreationTime
,NULL
);
55 statbuf
->st_atime
= FileTimeToUnixTime(&FileInformation
.ftLastAccessTime
,NULL
);
56 statbuf
->st_mtime
= FileTimeToUnixTime(&FileInformation
.ftLastWriteTime
,NULL
);
59 statbuf
->st_size
= FileInformation
.nFileSizeLow
;
60 statbuf
->st_mode
= S_IREAD
;
61 if (FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
62 statbuf
->st_mode
|= S_IFDIR
;
64 statbuf
->st_mode
|= S_IFREG
;
65 if (!(FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
))
66 statbuf
->st_mode
|= S_IWRITE
;
68 else if (dwFileType
== FILE_TYPE_CHAR
)
71 statbuf
->st_mode
= S_IFCHR
;
73 else if (dwFileType
== FILE_TYPE_PIPE
)
76 statbuf
->st_mode
= S_IFIFO
;
80 // dwFileType is FILE_TYPE_UNKNOWN or has a bad value