@@ -1009,7 +1009,7 @@ const char *retro_vfs_file_get_path_impl(
10091009 return stream -> orig_path ;
10101010}
10111011
1012- int retro_vfs_stat_impl (const char * path , int32_t * size )
1012+ int retro_vfs_stat_64_impl (const char * path , int64_t * size )
10131013{
10141014 int ret = RETRO_VFS_STAT_IS_VALID ;
10151015
@@ -1049,7 +1049,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
10491049 return 0 ;
10501050
10511051 if (size )
1052- * size = (int32_t )stat_buf .st_size ;
1052+ * size = (int64_t )stat_buf .st_size ;
10531053
10541054 if (FIO_S_ISDIR (stat_buf .st_mode ))
10551055 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1061,15 +1061,15 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
10611061 return 0 ;
10621062
10631063 if (size )
1064- * size = (int32_t )stat_buf .st_size ;
1064+ * size = (int64_t )stat_buf .st_size ;
10651065
10661066 if ((stat_buf .st_mode & S_IFMT ) == S_IFDIR )
10671067 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
10681068#elif defined(_WIN32 )
10691069 /* Windows
10701070 * Older MSVC _stat may fail on directory paths
10711071 * with a trailing backslash */
1072- struct _stat stat_buf ;
1072+ struct _stat64 stat_buf ;
10731073 char path_buf [PATH_MAX_LENGTH ];
10741074 const char * stat_path = path ;
10751075 size_t _len = strlcpy (path_buf , path , sizeof (path_buf ));
@@ -1118,7 +1118,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11181118 file_info = GetFileAttributesW (path_wide );
11191119
11201120 if (file_info == INVALID_FILE_ATTRIBUTES
1121- || _wstat (path_wide , & stat_buf ) != 0 )
1121+ || _wstat64 (path_wide , & stat_buf ) != 0 )
11221122 {
11231123 free (path_wide );
11241124 return 0 ;
@@ -1128,7 +1128,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11281128#endif
11291129
11301130 if (size )
1131- * size = (int32_t )stat_buf .st_size ;
1131+ * size = (int64_t )stat_buf .st_size ;
11321132
11331133 if (file_info & FILE_ATTRIBUTE_DIRECTORY )
11341134 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1148,21 +1148,27 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11481148 return 0 ;
11491149
11501150 if (size )
1151- * size = (int32_t )stat_buf .st_size ;
1151+ * size = (int64_t )stat_buf .st_size ;
11521152
11531153 if (S_ISDIR (stat_buf .st_mode ))
11541154 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
11551155 if (S_ISCHR (stat_buf .st_mode ))
11561156 ret |= RETRO_VFS_STAT_IS_CHARACTER_SPECIAL ;
11571157#else
11581158 /* Every other platform */
1159+ #if defined(_LARGEFILE64_SOURCE )
1160+ struct stat64 stat_buf ;
1161+ if (stat64 (path , & stat_buf ) < 0 )
1162+ return 0 ;
1163+ #else
11591164 struct stat stat_buf ;
11601165
11611166 if (stat (path , & stat_buf ) < 0 )
11621167 return 0 ;
1168+ #endif
11631169
11641170 if (size )
1165- * size = (int32_t )stat_buf .st_size ;
1171+ * size = (int64_t )stat_buf .st_size ;
11661172
11671173 if (S_ISDIR (stat_buf .st_mode ))
11681174 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1173,6 +1179,21 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11731179 return ret ;
11741180}
11751181
1182+ int retro_vfs_stat_impl (const char * path , int32_t * size )
1183+ {
1184+ int64_t size64 = 0 ;
1185+ int ret = retro_vfs_stat_64_impl (path , size ? & size64 : NULL );
1186+
1187+ /* if a file is larger than 2 GB, size64 will hold the correct value
1188+ * but the cast to int32_t will truncate it.
1189+ * new code should migrate to retro_vfs_stat_64_t
1190+ */
1191+ if (size )
1192+ * size = (int32_t )size64 ;
1193+
1194+ return ret ;
1195+ }
1196+
11761197#if defined(VITA )
11771198#define path_mkdir_err (ret ) (((ret) == SCE_ERROR_ERRNO_EEXIST))
11781199#elif defined(PSP ) || defined(PS2 ) || defined(_3DS ) || defined(WIIU ) || defined(SWITCH )
@@ -1499,7 +1520,7 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir)
14991520 {
15001521 char full [PATH_MAX_LENGTH ];
15011522 const char * name = retro_vfs_dirent_get_name_impl (rdir );
1502- int32_t sz = 0 ;
1523+ int64_t sz = 0 ;
15031524 int st = 0 ;
15041525
15051526 if (!name )
0 commit comments