@@ -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,14 +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 */
1070- struct _stat stat_buf ;
1070+ struct _stat64 stat_buf ;
10711071#if defined(LEGACY_WIN32 )
1072+ /* 32-bit only */
10721073 char * path_local = utf8_to_local_string_alloc (path );
10731074 DWORD file_info ;
10741075
@@ -1095,7 +1096,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
10951096 file_info = GetFileAttributesW (path_wide );
10961097
10971098 if (file_info == INVALID_FILE_ATTRIBUTES
1098- || _wstat (path_wide , & stat_buf ) != 0 )
1099+ || _wstat64 (path_wide , & stat_buf ) != 0 )
10991100 {
11001101 free (path_wide );
11011102 return 0 ;
@@ -1105,7 +1106,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11051106#endif
11061107
11071108 if (size )
1108- * size = (int32_t )stat_buf .st_size ;
1109+ * size = (int64_t )stat_buf .st_size ;
11091110
11101111 if (file_info & FILE_ATTRIBUTE_DIRECTORY )
11111112 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1125,21 +1126,27 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11251126 return 0 ;
11261127
11271128 if (size )
1128- * size = (int32_t )stat_buf .st_size ;
1129+ * size = (int64_t )stat_buf .st_size ;
11291130
11301131 if (S_ISDIR (stat_buf .st_mode ))
11311132 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
11321133 if (S_ISCHR (stat_buf .st_mode ))
11331134 ret |= RETRO_VFS_STAT_IS_CHARACTER_SPECIAL ;
11341135#else
11351136 /* Every other platform */
1137+ #if defined(_LARGEFILE64_SOURCE )
1138+ struct stat64 stat_buf ;
1139+ if (stat64 (path , & stat_buf ) < 0 )
1140+ return 0 ;
1141+ #else
11361142 struct stat stat_buf ;
11371143
11381144 if (stat (path , & stat_buf ) < 0 )
11391145 return 0 ;
1146+ #endif
11401147
11411148 if (size )
1142- * size = (int32_t )stat_buf .st_size ;
1149+ * size = (int64_t )stat_buf .st_size ;
11431150
11441151 if (S_ISDIR (stat_buf .st_mode ))
11451152 ret |= RETRO_VFS_STAT_IS_DIRECTORY ;
@@ -1150,6 +1157,21 @@ int retro_vfs_stat_impl(const char *path, int32_t *size)
11501157 return ret ;
11511158}
11521159
1160+ int retro_vfs_stat_impl (const char * path , int32_t * size )
1161+ {
1162+ int64_t size64 = 0 ;
1163+ int ret = retro_vfs_stat_64_impl (path , size ? & size64 : NULL );
1164+
1165+ /* if a file is larger than 2 GB, size64 will hold the correct value
1166+ * but the cast to int32_t will truncate it.
1167+ * new code should migrate to retro_vfs_stat_64_t
1168+ */
1169+ if (size )
1170+ * size = (int32_t )size64 ;
1171+
1172+ return ret ;
1173+ }
1174+
11531175#if defined(VITA )
11541176#define path_mkdir_err (ret ) (((ret) == SCE_ERROR_ERRNO_EEXIST))
11551177#elif defined(PSP ) || defined(PS2 ) || defined(_3DS ) || defined(WIIU ) || defined(SWITCH )
@@ -1476,7 +1498,7 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir)
14761498 {
14771499 char full [PATH_MAX_LENGTH ];
14781500 const char * name = retro_vfs_dirent_get_name_impl (rdir );
1479- int32_t sz = 0 ;
1501+ int64_t sz = 0 ;
14801502 int st = 0 ;
14811503
14821504 if (!name )
0 commit comments