Made parse_dir() return to current directory when done.

This commit is contained in:
n-a-c-h
2005-07-10 01:53:13 +00:00
parent 8cb11d0a29
commit 251758fbc3

View File

@@ -28,7 +28,9 @@ This is part of a toolkit used to assist in ZSNES development
bool parse_dir(const char *dir_loc, void (*func)(const char *, struct stat&))
{
if (!chdir(dir_loc)) //chdir() returns 0 on success
char cwd[16384];
if (getcwd(cwd, sizeof(cwd)) && !chdir(dir_loc)) //chdir() returns 0 on success
{
DIR *curDir = opendir(".");
dirent *curFile;
@@ -47,16 +49,14 @@ bool parse_dir(const char *dir_loc, void (*func)(const char *, struct stat&))
//Directory
if (S_ISDIR(stat_buffer.st_mode))
{
if (parse_dir(filename, func))
{
chdir("..");
}
parse_dir(filename, func);
continue;
}
func(filename, stat_buffer);
}
closedir(curDir);
chdir(cwd);
return(true);
}
return(false);