blob: e3311f28ae7554d2b648a83d5cb12c25942c96c0 [file] [log] [blame]
Pali Rohárcff91bb2025-04-13 18:34:42 +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 <stdlib.h>
9#include <stdint.h>
10#include <errno.h>
11
12char *__mingw_fix_stat_path(const char *_path);
13
14/* For pre-msvcr110 builds, we cannot use _stat64i32() function as it does
15 * not signal EOVERFLOW when file size does not fit into the st_size field,
16 * as it is required by POSIX stat() function.
17 * This file is used only for pre-msvcr110 builds.
18 */
19int __cdecl stat64i32(const char *_Filename, struct _stat64i32 *_Stat);
20int __cdecl stat64i32(const char *_Filename, struct _stat64i32 *_Stat)
21{
22 struct _stat64 st;
23 char *_path = __mingw_fix_stat_path(_Filename);
24 int ret = _stat64(_path, &st);
25 if (_path != _Filename)
26 free(_path);
27 if (ret != 0)
28 return ret;
29 if (st.st_size > UINT32_MAX) {
30 errno = EOVERFLOW;
31 return -1;
32 }
33 _Stat->st_dev=st.st_dev;
34 _Stat->st_ino=st.st_ino;
35 _Stat->st_mode=st.st_mode;
36 _Stat->st_nlink=st.st_nlink;
37 _Stat->st_uid=st.st_uid;
38 _Stat->st_gid=st.st_gid;
39 _Stat->st_rdev=st.st_rdev;
40 _Stat->st_size=(_off_t) st.st_size;
41 _Stat->st_atime=st.st_atime;
42 _Stat->st_mtime=st.st_mtime;
43 _Stat->st_ctime=st.st_ctime;
44 return 0;
45}
46int (__cdecl *__MINGW_IMP_SYMBOL(stat64i32))(const char *, struct _stat64i32 *) = stat64i32;
47
48/* On 64-bit systems is stat() function ABI compatible with stat64i32() function */
49#ifdef _WIN64
50#undef stat
51struct stat;
52int __attribute__ ((alias ("stat64i32"))) __cdecl stat(const char *name, struct stat *stat);
53extern int __attribute__ ((alias (__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(stat64i32))))) (__cdecl *__MINGW_IMP_SYMBOL(stat))(const char *name, struct stat *stat);
54#endif