1 /* $Id: fstat.c,v 1.9 2002/05/07 22:31:26 hbirr Exp $
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
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>
19 int _fstat(int fd
, struct stat
*statbuf
)
21 BY_HANDLE_FILE_INFORMATION FileInformation
;
31 if ((void*)-1 == (handle
= _get_osfhandle(fd
)))
37 memset (statbuf
, 0, sizeof(struct stat
));
39 dwFileType
= GetFileType(handle
);
41 if (dwFileType
== FILE_TYPE_DISK
)
43 if (!GetFileInformationByHandle(handle
,&FileInformation
))
48 statbuf
->st_ctime
= FileTimeToUnixTime(&FileInformation
.ftCreationTime
,NULL
);
49 statbuf
->st_atime
= FileTimeToUnixTime(&FileInformation
.ftLastAccessTime
,NULL
);
50 statbuf
->st_mtime
= FileTimeToUnixTime(&FileInformation
.ftLastWriteTime
,NULL
);
53 statbuf
->st_size
= FileInformation
.nFileSizeLow
;
54 statbuf
->st_mode
= S_IREAD
;
55 if (FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
56 statbuf
->st_mode
|= S_IFDIR
;
58 statbuf
->st_mode
|= S_IFREG
;
59 if (!(FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
)) statbuf
->st_mode
|= S_IWRITE
;
61 else if (dwFileType
== FILE_TYPE_CHAR
)
64 statbuf
->st_mode
= S_IFCHR
;
66 else if (dwFileType
== FILE_TYPE_PIPE
)
69 statbuf
->st_mode
= S_IFIFO
;
73 // dwFileType is FILE_TYPE_UNKNOWN or has a bad value
80 __int64
_fstati64 (int fd
, struct _stati64
* statbuf
)
82 BY_HANDLE_FILE_INFORMATION FileInformation
;
92 if ((void*)-1 == (handle
= _get_osfhandle(fd
)))
98 memset(statbuf
, 0, sizeof(struct _stati64
));
100 dwFileType
= GetFileType(handle
);
102 if (dwFileType
== FILE_TYPE_DISK
)
104 if (!GetFileInformationByHandle(handle
,&FileInformation
))
109 statbuf
->st_ctime
= FileTimeToUnixTime(&FileInformation
.ftCreationTime
,NULL
);
110 statbuf
->st_atime
= FileTimeToUnixTime(&FileInformation
.ftLastAccessTime
,NULL
);
111 statbuf
->st_mtime
= FileTimeToUnixTime(&FileInformation
.ftLastWriteTime
,NULL
);
113 statbuf
->st_dev
= fd
;
114 statbuf
->st_size
= (((__int64
)FileInformation
.nFileSizeHigh
) << 32) +
115 FileInformation
.nFileSizeLow
;
116 statbuf
->st_mode
= S_IREAD
;
117 if (FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
118 statbuf
->st_mode
|= S_IFDIR
;
120 statbuf
->st_mode
|= S_IFREG
;
121 if (!(FileInformation
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
)) statbuf
->st_mode
|= S_IWRITE
;
123 else if (dwFileType
== FILE_TYPE_CHAR
)
125 statbuf
->st_dev
= fd
;
126 statbuf
->st_mode
= S_IFCHR
;
128 else if (dwFileType
== FILE_TYPE_PIPE
)
130 statbuf
->st_dev
= fd
;
131 statbuf
->st_mode
= S_IFIFO
;
135 // dwFileType is FILE_TYPE_UNKNOWN or has a bad value