@@ -1040,7 +1040,7 @@ const char *retro_vfs_file_get_path_impl(
10401040 return stream -> orig_path ;
10411041}
10421042
1043- int retro_vfs_stat_impl (const char * path , int32_t * size )
1043+ int retro_vfs_stat_64_impl (const char * path , int64_t * size )
10441044{
10451045 int ret = RETRO_VFS_STAT_IS_VALID ;
10461046
@@ -1088,7 +1088,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
10881088 return 0 ;
10891089
10901090 if (size )
1091- * size = (int32_t )stat_buf .st_size ;
1091+ * size = (int64_t )stat_buf .st_size ;
10921092
10931093 if (FIO_S_ISDIR (stat_buf .st_mode ))
10941094 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1100,14 +1100,15 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11001100 return 0 ;
11011101
11021102 if (size )
1103- * size = (int32_t )stat_buf .st_size ;
1103+ * size = (int64_t )stat_buf .st_size ;
11041104
11051105 if ((stat_buf .st_mode & S_IFMT ) == S_IFDIR )
11061106 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
11071107#elif defined(_WIN32 )
11081108 /* Windows */
1109- struct _stat stat_buf ;
1109+ struct _stat64 stat_buf ;
11101110#if defined(LEGACY_WIN32 )
1111+ /* 32-bit only */
11111112 char * path_local = utf8_to_local_string_alloc (path );
11121113 DWORD file_info = GetFileAttributes (path_local );
11131114
@@ -1120,7 +1121,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11201121 wchar_t * path_wide = utf8_to_utf16_string_alloc (path );
11211122 DWORD file_info = GetFileAttributesW (path_wide );
11221123
1123- _wstat (path_wide , & stat_buf );
1124+ _wstat64 (path_wide , & stat_buf );
11241125
11251126 if (path_wide )
11261127 free (path_wide );
@@ -1129,7 +1130,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11291130 return 0 ;
11301131
11311132 if (size )
1132- * size = (int32_t )stat_buf .st_size ;
1133+ * size = (int64_t )stat_buf .st_size ;
11331134
11341135 if (file_info & FILE_ATTRIBUTE_DIRECTORY )
11351136 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1157,21 +1158,27 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11571158 free (path_buf );
11581159
11591160 if (size )
1160- * size = (int32_t )stat_buf .st_size ;
1161+ * size = (int64_t )stat_buf .st_size ;
11611162
11621163 if (S_ISDIR (stat_buf .st_mode ))
11631164 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
11641165 if (S_ISCHR (stat_buf .st_mode ))
11651166 ret |= RETRO_VFS_STAT_IS_CHARACTER_SPECIAL ;
11661167#else
11671168 /* Every other platform */
1169+ #if defined(_LARGEFILE64_SOURCE )
1170+ struct stat64 stat_buf ;
1171+ if (stat64 (path , & stat_buf ) < 0 )
1172+ return 0 ;
1173+ #else
11681174 struct stat stat_buf ;
11691175
11701176 if (stat (path , & stat_buf ) < 0 )
11711177 return 0 ;
1178+ #endif
11721179
11731180 if (size )
1174- * size = (int32_t )stat_buf .st_size ;
1181+ * size = (int64_t )stat_buf .st_size ;
11751182
11761183 if (S_ISDIR (stat_buf .st_mode ))
11771184 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1182,6 +1189,21 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11821189 return ret ;
11831190}
11841191
1192+ int retro_vfs_stat_impl (const char * path , int32_t * size )
1193+ {
1194+ int64_t size64 = 0 ;
1195+ int ret = retro_vfs_stat_64_impl (path , size ? & size64 : NULL );
1196+
1197+ /* if a file is larger than 2 GB, size64 will hold the correct value
1198+ * but the cast to int32_t will truncate it.
1199+ * new code should migrate to retro_vfs_stat_64_t
1200+ */
1201+ if (size )
1202+ * size = (int32_t )size64 ;
1203+
1204+ return ret ;
1205+ }
1206+
11851207#if defined(VITA )
11861208#define path_mkdir_err (ret ) (((ret) == SCE_ERROR_ERRNO_EEXIST))
11871209#elif defined(PSP ) || defined(PS2 ) || defined(_3DS ) || defined(WIIU ) || defined(SWITCH )
@@ -1523,7 +1545,7 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir)
15231545 {
15241546 char full [PATH_MAX_LENGTH ];
15251547 const char * name = retro_vfs_dirent_get_name_impl (rdir );
1526- int32_t sz = 0 ;
1548+ int64_t sz = 0 ;
15271549 int st = 0 ;
15281550
15291551 if (!name )
0 commit comments