1 /* $Id: fstat.c,v 1.12 2002/11/29 12:27:49 robd Exp $
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
12 #include <msvcrt/sys/types.h>
13 #include <msvcrt/sys/stat.h>
14 #include <msvcrt/fcntl.h>
15 #include <msvcrt/string.h>
16 #include <msvcrt/errno.h>
17 #include <msvcrt/internal/file.h>
20 int _fstat(int fd
, struct stat
* statbuf
)
22 BY_HANDLE_FILE_INFORMATION FileInformation
;
29 if (!GetFileInformationByHandle(_get_osfhandle(fd
),&FileInformation
)) {
33 statbuf
->st_ctime
= FileTimeToUnixTime(&FileInformation
.ftCreationTime
,NULL
);
34 statbuf
->st_atime
= FileTimeToUnixTime(&FileInformation
.ftLastAccessTime
,NULL
);
35 statbuf
->st_mtime
= FileTimeToUnixTime(&FileInformation
.ftLastWriteTime
,NULL
);
36 if (statbuf
->st_atime
==0)
37 statbuf
->st_atime
= statbuf
->st_mtime
;
38 if (statbuf
->st_ctime
==0)
39 statbuf
->st_ctime
= statbuf
->st_mtime
;
41 statbuf
->st_dev
= FileInformation
.dwVolumeSerialNumber
;
42 statbuf
->st_size
= FileInformation
.nFileSizeLow
;
43 statbuf
->st_nlink
= FileInformation
.nNumberOfLinks
;
44 statbuf
->st_mode
= S_IREAD
;
45 if (FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
46 statbuf
->st_mode
|= S_IFDIR
| S_IEXEC
;
48 statbuf
->st_mode
|= S_IFREG
;
49 if (!(FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
))
50 statbuf
->st_mode
|= S_IWRITE
;