blob: 28c5d73c1f55e5968931cf34a89f1557094a620f [file] [log] [blame]
Pali Rohárb06fd9d2025-04-13 18:34:32 +02001/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <sys/stat.h>
8#include <io.h>
9#include <windows.h>
10
11#include "filetime_to_time64.h"
12
13static int __cdecl emu__fstat64(int fd, struct _stat64 *stat)
14{
15 BY_HANDLE_FILE_INFORMATION fi;
16 struct _stat32 st;
17 int ret = _fstat32(fd, &st);
18 if (ret != 0)
19 return ret;
20 stat->st_dev = st.st_dev;
21 stat->st_ino = st.st_ino;
22 stat->st_mode = st.st_mode;
23 stat->st_nlink = st.st_nlink;
24 stat->st_uid = st.st_uid;
25 stat->st_gid = st.st_gid;
26 stat->st_rdev = st.st_rdev;
27 if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &fi)) {
28 stat->st_size = ((_off64_t)fi.nFileSizeHigh << 32) | fi.nFileSizeLow;
29 stat->st_atime = filetime_to_time64(&fi.ftLastAccessTime);
30 stat->st_mtime = filetime_to_time64(&fi.ftLastWriteTime);
31 stat->st_ctime = filetime_to_time64(&fi.ftCreationTime);
32 } else {
33 stat->st_size = st.st_size; /* truncated value */
34 stat->st_atime = st.st_atime; /* invalid value -1 */
35 stat->st_mtime = st.st_mtime; /* invalid value -1 */
36 stat->st_ctime = st.st_ctime; /* invalid value -1 */
37 }
38 return 0;
39}
40
41#define RETT int
42#define FUNC _fstat64
43#define ARGS int fd, struct _stat64 *stat
44#define CALL fd, stat
45#include "msvcrt_or_emu_glue.h"
46
Pali Rohár07e34532025-04-13 18:34:40 +020047int __attribute__ ((alias ("_fstat64"))) __cdecl fstat64(int, struct stat64 *);
48extern int __attribute__ ((alias (__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(_fstat64))))) (__cdecl *__MINGW_IMP_SYMBOL(fstat64))(int, struct stat64 *);