@@ -1007,7 +1007,7 @@ const char *retro_vfs_file_get_path_impl(
10071007 return stream -> orig_path ;
10081008}
10091009
1010- int retro_vfs_stat_impl (const char * path , int32_t * size )
1010+ int retro_vfs_stat_64_impl (const char * path , int64_t * size )
10111011{
10121012 int ret = RETRO_VFS_STAT_IS_VALID ;
10131013
@@ -1047,7 +1047,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
10471047 return 0 ;
10481048
10491049 if (size )
1050- * size = (int32_t )stat_buf .st_size ;
1050+ * size = (int64_t )stat_buf .st_size ;
10511051
10521052 if (FIO_S_ISDIR (stat_buf .st_mode ))
10531053 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1059,15 +1059,15 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
10591059 return 0 ;
10601060
10611061 if (size )
1062- * size = (int32_t )stat_buf .st_size ;
1062+ * size = (int64_t )stat_buf .st_size ;
10631063
10641064 if ((stat_buf .st_mode & S_IFMT ) == S_IFDIR )
10651065 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
10661066#elif defined(_WIN32 )
10671067 /* Windows
10681068 * Older MSVC _stat may fail on directory paths
10691069 * with a trailing backslash */
1070- struct _stat stat_buf ;
1070+ struct _stat64 stat_buf ;
10711071 char path_buf [PATH_MAX_LENGTH ];
10721072 const char * stat_path = path ;
10731073 DWORD file_info ;
@@ -1120,7 +1120,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11201120 file_info = GetFileAttributesW (path_wide );
11211121
11221122 if (file_info == INVALID_FILE_ATTRIBUTES
1123- || _wstat (path_wide , & stat_buf ) != 0 )
1123+ || _wstat64 (path_wide , & stat_buf ) != 0 )
11241124 {
11251125 free (path_wide );
11261126 return 0 ;
@@ -1130,7 +1130,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11301130#endif
11311131
11321132 if (size )
1133- * size = (int32_t )stat_buf .st_size ;
1133+ * size = (int64_t )stat_buf .st_size ;
11341134
11351135 if (file_info & FILE_ATTRIBUTE_DIRECTORY )
11361136 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1150,21 +1150,27 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11501150 return 0 ;
11511151
11521152 if (size )
1153- * size = (int32_t )stat_buf .st_size ;
1153+ * size = (int64_t )stat_buf .st_size ;
11541154
11551155 if (S_ISDIR (stat_buf .st_mode ))
11561156 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
11571157 if (S_ISCHR (stat_buf .st_mode ))
11581158 ret |= RETRO_VFS_STAT_IS_CHARACTER_SPECIAL ;
11591159#else
11601160 /* Every other platform */
1161+ #if defined(_LARGEFILE64_SOURCE )
1162+ struct stat64 stat_buf ;
1163+ if (stat64 (path , & stat_buf ) < 0 )
1164+ return 0 ;
1165+ #else
11611166 struct stat stat_buf ;
11621167
11631168 if (stat (path , & stat_buf ) < 0 )
11641169 return 0 ;
1170+ #endif
11651171
11661172 if (size )
1167- * size = (int32_t )stat_buf .st_size ;
1173+ * size = (int64_t )stat_buf .st_size ;
11681174
11691175 if (S_ISDIR (stat_buf .st_mode ))
11701176 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1175,6 +1181,21 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11751181 return ret ;
11761182}
11771183
1184+ int retro_vfs_stat_impl (const char * path , int32_t * size )
1185+ {
1186+ int64_t size64 = 0 ;
1187+ int ret = retro_vfs_stat_64_impl (path , size ? & size64 : NULL );
1188+
1189+ /* if a file is larger than 2 GB, size64 will hold the correct value
1190+ * but the cast to int32_t will truncate it.
1191+ * new code should migrate to retro_vfs_stat_64_t
1192+ */
1193+ if (size )
1194+ * size = (int32_t )size64 ;
1195+
1196+ return ret ;
1197+ }
1198+
11781199#if defined(VITA )
11791200#define path_mkdir_err (ret ) (((ret) == SCE_ERROR_ERRNO_EEXIST))
11801201#elif defined(PSP ) || defined(PS2 ) || defined(_3DS ) || defined(WIIU ) || defined(SWITCH )
@@ -1498,7 +1519,7 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir)
14981519 {
14991520 char full [PATH_MAX_LENGTH ];
15001521 const char * name = retro_vfs_dirent_get_name_impl (rdir );
1501- int32_t sz = 0 ;
1522+ int64_t sz = 0 ;
15021523 int st = 0 ;
15031524
15041525 if (!name )
0 commit comments