@@ -1043,7 +1043,7 @@ const char *retro_vfs_file_get_path_impl(
10431043 return stream -> orig_path ;
10441044}
10451045
1046- int retro_vfs_stat_impl (const char * path , int32_t * size )
1046+ int retro_vfs_stat_64_impl (const char * path , int64_t * size )
10471047{
10481048 int ret = RETRO_VFS_STAT_IS_VALID ;
10491049
@@ -1091,7 +1091,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
10911091 return 0 ;
10921092
10931093 if (size )
1094- * size = (int32_t )stat_buf .st_size ;
1094+ * size = (int64_t )stat_buf .st_size ;
10951095
10961096 if (FIO_S_ISDIR (stat_buf .st_mode ))
10971097 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1103,14 +1103,15 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11031103 return 0 ;
11041104
11051105 if (size )
1106- * size = (int32_t )stat_buf .st_size ;
1106+ * size = (int64_t )stat_buf .st_size ;
11071107
11081108 if ((stat_buf .st_mode & S_IFMT ) == S_IFDIR )
11091109 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
11101110#elif defined(_WIN32 )
11111111 /* Windows */
1112- struct _stat stat_buf ;
1112+ struct _stat64 stat_buf ;
11131113#if defined(LEGACY_WIN32 )
1114+ /* 32-bit only */
11141115 char * path_local = utf8_to_local_string_alloc (path );
11151116 DWORD file_info = GetFileAttributes (path_local );
11161117
@@ -1123,7 +1124,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11231124 wchar_t * path_wide = utf8_to_utf16_string_alloc (path );
11241125 DWORD file_info = GetFileAttributesW (path_wide );
11251126
1126- _wstat (path_wide , & stat_buf );
1127+ _wstat64 (path_wide , & stat_buf );
11271128
11281129 if (path_wide )
11291130 free (path_wide );
@@ -1132,7 +1133,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11321133 return 0 ;
11331134
11341135 if (size )
1135- * size = (int32_t )stat_buf .st_size ;
1136+ * size = (int64_t )stat_buf .st_size ;
11361137
11371138 if (file_info & FILE_ATTRIBUTE_DIRECTORY )
11381139 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1160,21 +1161,27 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11601161 free (path_buf );
11611162
11621163 if (size )
1163- * size = (int32_t )stat_buf .st_size ;
1164+ * size = (int64_t )stat_buf .st_size ;
11641165
11651166 if (S_ISDIR (stat_buf .st_mode ))
11661167 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
11671168 if (S_ISCHR (stat_buf .st_mode ))
11681169 ret |= RETRO_VFS_STAT_IS_CHARACTER_SPECIAL ;
11691170#else
11701171 /* Every other platform */
1172+ #if defined(_LARGEFILE64_SOURCE )
1173+ struct stat64 stat_buf ;
1174+ if (stat64 (path , & stat_buf ) < 0 )
1175+ return 0 ;
1176+ #else
11711177 struct stat stat_buf ;
11721178
11731179 if (stat (path , & stat_buf ) < 0 )
11741180 return 0 ;
1181+ #endif
11751182
11761183 if (size )
1177- * size = (int32_t )stat_buf .st_size ;
1184+ * size = (int64_t )stat_buf .st_size ;
11781185
11791186 if (S_ISDIR (stat_buf .st_mode ))
11801187 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1185,6 +1192,21 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11851192 return ret ;
11861193}
11871194
1195+ int retro_vfs_stat_impl (const char * path , int32_t * size )
1196+ {
1197+ int64_t size64 = 0 ;
1198+ int ret = retro_vfs_stat_64_impl (path , size ? & size64 : NULL );
1199+
1200+ /* if a file is larger than 2 GB, size64 will hold the correct value
1201+ * but the cast to int32_t will truncate it.
1202+ * new code should migrate to retro_vfs_stat_64_t
1203+ */
1204+ if (size )
1205+ * size = (int32_t )size64 ;
1206+
1207+ return ret ;
1208+ }
1209+
11881210#if defined(VITA )
11891211#define path_mkdir_err (ret ) (((ret) == SCE_ERROR_ERRNO_EEXIST))
11901212#elif defined(PSP ) || defined(PS2 ) || defined(_3DS ) || defined(WIIU ) || defined(SWITCH )
@@ -1526,7 +1548,7 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir)
15261548 {
15271549 char full [PATH_MAX_LENGTH ];
15281550 const char * name = retro_vfs_dirent_get_name_impl (rdir );
1529- int32_t sz = 0 ;
1551+ int64_t sz = 0 ;
15301552 int st = 0 ;
15311553
15321554 if (!name )
0 commit comments