From b1b33f7db00102de7551aaf450ca40360c012b88 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 27 May 2004 04:48:31 +0000 Subject: [PATCH] add opendir() error check to fix readdir() crash --- stepmania/src/RageFileDriverDirectHelpers.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stepmania/src/RageFileDriverDirectHelpers.cpp b/stepmania/src/RageFileDriverDirectHelpers.cpp index 67e1084612..695b99b580 100644 --- a/stepmania/src/RageFileDriverDirectHelpers.cpp +++ b/stepmania/src/RageFileDriverDirectHelpers.cpp @@ -282,7 +282,16 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path ) close( OldDir ); return; } + DIR *d = opendir("."); + if( d == NULL ) + { + LOG->MapLog("opendir " + root+"/"+sPath, "Couldn't opendir(%s%s): %s", root.c_str(), sPath.c_str(), strerror(errno) ); + if( fchdir( OldDir ) == -1 ) + RageException::Throw( "Couldn't fchdir(): %s", strerror(errno) ); + close( OldDir ); + return; + } while(struct dirent *ent = readdir(d)) {