Replace the deprecated readdir_r function
This commit is contained in:
parent
9e0b6f8b53
commit
1543d042cb
|
@ -271,40 +271,37 @@ int FFileDialog::readDir()
|
||||||
|
|
||||||
while ( true )
|
while ( true )
|
||||||
{
|
{
|
||||||
int retval;
|
errno = 0;
|
||||||
struct dirent next;
|
struct dirent* next = readdir(directory_stream);
|
||||||
struct dirent* result;
|
|
||||||
|
|
||||||
retval = readdir_r(directory_stream, &next, &result);
|
if ( next )
|
||||||
|
|
||||||
if ( result && retval == 0 )
|
|
||||||
{
|
{
|
||||||
if ( next.d_name[0] == '.' && next.d_name[1] == '\0' )
|
if ( next->d_name[0] == '.' && next->d_name[1] == '\0' )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( ! show_hidden
|
if ( ! show_hidden
|
||||||
&& next.d_name[0] == '.'
|
&& next->d_name[0] == '.'
|
||||||
&& next.d_name[1] != '\0'
|
&& next->d_name[1] != '\0'
|
||||||
&& next.d_name[1] != '.' )
|
&& next->d_name[1] != '.' )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dir[0] == '/' && dir[1] == '\0'
|
if ( dir[0] == '/' && dir[1] == '\0'
|
||||||
&& std::strcmp(next.d_name, "..") == 0 )
|
&& std::strcmp(next->d_name, "..") == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
dir_entry entry;
|
dir_entry entry;
|
||||||
entry.name = strdup(next.d_name);
|
entry.name = strdup(next->d_name);
|
||||||
entry.type = next.d_type;
|
entry.type = next->d_type;
|
||||||
|
|
||||||
if ( next.d_type == DT_LNK ) // symbolic link
|
if ( next->d_type == DT_LNK ) // symbolic link
|
||||||
{
|
{
|
||||||
char resolved_path[MAXPATHLEN] = {};
|
char resolved_path[MAXPATHLEN] = {};
|
||||||
char symLink[MAXPATHLEN] = {};
|
char symLink[MAXPATHLEN] = {};
|
||||||
std::strncpy (symLink, dir, sizeof(symLink) - 1);
|
std::strncpy (symLink, dir, sizeof(symLink) - 1);
|
||||||
std::strncat ( symLink
|
std::strncat ( symLink
|
||||||
, next.d_name
|
, next->d_name
|
||||||
, sizeof(symLink) - std::strlen(symLink) - 1);
|
, sizeof(symLink) - std::strlen(symLink) - 1);
|
||||||
|
|
||||||
if ( realpath(symLink, resolved_path) != 0 ) // follow link
|
if ( realpath(symLink, resolved_path) != 0 ) // follow link
|
||||||
|
@ -326,11 +323,11 @@ int FFileDialog::readDir()
|
||||||
else
|
else
|
||||||
std::free(entry.name);
|
std::free(entry.name);
|
||||||
}
|
}
|
||||||
else if ( retval > 0 )
|
else if ( errno != 0 )
|
||||||
{
|
{
|
||||||
FMessageBox::error (this, "Reading directory\n" + directory);
|
FMessageBox::error (this, "Reading directory\n" + directory);
|
||||||
|
|
||||||
if ( retval == EBADF ) // Invalid directory stream descriptor
|
if ( errno == EOVERFLOW ) // Value too large to be stored in data type
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue