Skip to content

Commit

Permalink
- Use new dirent extension when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Apr 22, 2024
1 parent f2a7139 commit 9365cf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cube/swiss/source/devices/ftp/deviceHandler-FTP.c
Expand Up @@ -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;
Expand All @@ -120,14 +124,18 @@ 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;
}
}
} while(entry || errno == EOVERFLOW);

#undef fstat
closedir(dp);
return i;
}
Expand Down
10 changes: 9 additions & 1 deletion cube/swiss/source/devices/smb/deviceHandler-SMB.c
Expand Up @@ -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;
Expand All @@ -124,14 +128,18 @@ 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;
}
}
} while(entry || errno == EOVERFLOW);

#undef fstat
closedir(dp);
return i;
}
Expand Down

0 comments on commit 9365cf1

Please sign in to comment.