From 1efefa849363af3a1713470e18bc4ca0467c9e9f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 16 Sep 2003 02:45:49 +0000 Subject: [PATCH] Use fchdir. --- stepmania/src/RageUtil_FileDB.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stepmania/src/RageUtil_FileDB.cpp b/stepmania/src/RageUtil_FileDB.cpp index cd8ad6e94c..8dced999c5 100644 --- a/stepmania/src/RageUtil_FileDB.cpp +++ b/stepmania/src/RageUtil_FileDB.cpp @@ -14,6 +14,7 @@ #if !defined(WIN32) #include +#include #endif @@ -72,13 +73,16 @@ void FileSet::LoadFromDir(const CString &dir) } while( FindNextFile( hFind, &fd ) ); FindClose(hFind); #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 ) { /* Only log once per dir. */ if( LOG ) LOG->MapLog("chdir " + dir, "Couldn't chdir(%s): %s", dir.c_str(), strerror(errno) ); + close( OldDir ); return; } DIR *d = opendir("."); @@ -111,7 +115,9 @@ void FileSet::LoadFromDir(const CString &dir) } closedir(d); - chdir( OldDir ); + if( fchdir( OldDir ) == -1 ) + RageException::Throw( "Couldn't fchdir(): %s", strerror(errno) ); + close( OldDir ); #endif }