From 9365cf1fcf247f13b1dc2096920be93fc45646b9 Mon Sep 17 00:00:00 2001 From: Extrems Date: Mon, 22 Apr 2024 13:24:09 -0400 Subject: [PATCH] - Use new dirent extension when available. --- cube/swiss/source/devices/ftp/deviceHandler-FTP.c | 10 +++++++++- cube/swiss/source/devices/smb/deviceHandler-SMB.c | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cube/swiss/source/devices/ftp/deviceHandler-FTP.c b/cube/swiss/source/devices/ftp/deviceHandler-FTP.c index 82ac37fa..60991897 100644 --- a/cube/swiss/source/devices/ftp/deviceHandler-FTP.c +++ b/cube/swiss/source/devices/ftp/deviceHandler-FTP.c @@ -93,7 +93,11 @@ s32 deviceHandler_FTP_readDir(file_handle* ffile, file_handle** dir, u32 type){ DIR* dp = opendir( ffile->name ); if(!dp) return -1; struct dirent *entry; + #ifdef _DIRENT_HAVE_D_STAT + #define fstat entry->d_stat + #else struct stat fstat; + #endif // Set everything up to read int num_entries = 1, i = 1; @@ -120,7 +124,10 @@ s32 deviceHandler_FTP_readDir(file_handle* ffile, file_handle** dir, u32 type){ } memset(&(*dir)[i], 0, sizeof(file_handle)); if(concat_path((*dir)[i].name, ffile->name, entry->d_name) < PATHNAME_MAX - && !stat((*dir)[i].name, &fstat) && fstat.st_size <= UINT32_MAX) { + #ifndef _DIRENT_HAVE_D_STAT + && !stat((*dir)[i].name, &fstat) + #endif + && fstat.st_size <= UINT32_MAX) { (*dir)[i].size = fstat.st_size; (*dir)[i].fileAttrib = S_ISDIR(fstat.st_mode) ? IS_DIR : IS_FILE; ++i; @@ -128,6 +135,7 @@ s32 deviceHandler_FTP_readDir(file_handle* ffile, file_handle** dir, u32 type){ } } while(entry || errno == EOVERFLOW); + #undef fstat closedir(dp); return i; } diff --git a/cube/swiss/source/devices/smb/deviceHandler-SMB.c b/cube/swiss/source/devices/smb/deviceHandler-SMB.c index 9e90e302..54176c76 100644 --- a/cube/swiss/source/devices/smb/deviceHandler-SMB.c +++ b/cube/swiss/source/devices/smb/deviceHandler-SMB.c @@ -97,7 +97,11 @@ s32 deviceHandler_SMB_readDir(file_handle* ffile, file_handle** dir, u32 type){ DIR* dp = opendir( ffile->name ); if(!dp) return -1; struct dirent *entry; + #ifdef _DIRENT_HAVE_D_STAT + #define fstat entry->d_stat + #else struct stat fstat; + #endif // Set everything up to read int num_entries = 1, i = 1; @@ -124,7 +128,10 @@ s32 deviceHandler_SMB_readDir(file_handle* ffile, file_handle** dir, u32 type){ } memset(&(*dir)[i], 0, sizeof(file_handle)); if(concat_path((*dir)[i].name, ffile->name, entry->d_name) < PATHNAME_MAX - && !stat((*dir)[i].name, &fstat) && fstat.st_size <= UINT32_MAX) { + #ifndef _DIRENT_HAVE_D_STAT + && !stat((*dir)[i].name, &fstat) + #endif + && fstat.st_size <= UINT32_MAX) { (*dir)[i].size = fstat.st_size; (*dir)[i].fileAttrib = S_ISDIR(fstat.st_mode) ? IS_DIR : IS_FILE; ++i; @@ -132,6 +139,7 @@ s32 deviceHandler_SMB_readDir(file_handle* ffile, file_handle** dir, u32 type){ } } while(entry || errno == EOVERFLOW); + #undef fstat closedir(dp); return i; }