Use fchdir.
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#if !defined(WIN32)
|
#if !defined(WIN32)
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -72,13 +73,16 @@ void FileSet::LoadFromDir(const CString &dir)
|
|||||||
} while( FindNextFile( hFind, &fd ) );
|
} while( FindNextFile( hFind, &fd ) );
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
#else
|
#else
|
||||||
CString OldDir = GetCwd();
|
int OldDir = open(".", O_RDONLY);
|
||||||
|
if( OldDir == -1 )
|
||||||
|
RageException::Throw( "Couldn't open(.): %s", strerror(errno) );
|
||||||
|
|
||||||
if( chdir(dir.c_str()) == -1 )
|
if( chdir(dir.c_str()) == -1 )
|
||||||
{
|
{
|
||||||
/* Only log once per dir. */
|
/* Only log once per dir. */
|
||||||
if( LOG )
|
if( LOG )
|
||||||
LOG->MapLog("chdir " + dir, "Couldn't chdir(%s): %s", dir.c_str(), strerror(errno) );
|
LOG->MapLog("chdir " + dir, "Couldn't chdir(%s): %s", dir.c_str(), strerror(errno) );
|
||||||
|
close( OldDir );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DIR *d = opendir(".");
|
DIR *d = opendir(".");
|
||||||
@@ -111,7 +115,9 @@ void FileSet::LoadFromDir(const CString &dir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
closedir(d);
|
closedir(d);
|
||||||
chdir( OldDir );
|
if( fchdir( OldDir ) == -1 )
|
||||||
|
RageException::Throw( "Couldn't fchdir(): %s", strerror(errno) );
|
||||||
|
close( OldDir );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user