move old cruft
[reactos.git] / reactos / lib / crtdll / old cruft / sys_stat / fstat.c
1 /* $Id$
2 *
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
8 * UPDATE HISTORY:
9 * 28/12/98: Created
10 */
11
12 #include <precomp.h>
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>
19
20
21 /*
22 * @implemented
23 */
24 int _fstat(int fd, struct stat* statbuf)
25 {
26 BY_HANDLE_FILE_INFORMATION FileInformation;
27
28 if (!statbuf) {
29 __set_errno(EINVAL);
30 return -1;
31 }
32
33 if (!GetFileInformationByHandle(_get_osfhandle(fd),&FileInformation)) {
34 __set_errno (EBADF);
35 return -1;
36 }
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;
44
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;
51 else
52 statbuf->st_mode |= S_IFREG;
53 if (!(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
54 statbuf->st_mode |= S_IWRITE;
55 return 0;
56 }