replace file calls with standard ones

This commit is contained in:
dborth 2011-01-20 02:52:56 +00:00
parent 5d7331ead0
commit d968149ac5
2 changed files with 27 additions and 27 deletions

View File

@ -16,7 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <sys/dir.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <zlib.h> #include <zlib.h>
#include <malloc.h> #include <malloc.h>
@ -55,7 +55,7 @@ bool isMounted[7] = { false, false, false, false, false, false, false };
// folder parsing thread // folder parsing thread
static lwp_t parsethread = LWP_THREAD_NULL; static lwp_t parsethread = LWP_THREAD_NULL;
static DIR_ITER * dirIter = NULL; static DIR *dir = NULL;
static bool parseHalt = true; static bool parseHalt = true;
static bool parseFilter = true; static bool parseFilter = true;
bool ParseDirEntries(); bool ParseDirEntries();
@ -480,27 +480,27 @@ static char *GetExt(char *file)
bool ParseDirEntries() bool ParseDirEntries()
{ {
if(!dirIter) if(!dir)
return false; return false;
char filename[MAXPATHLEN];
char *ext; char *ext;
struct dirent *entry;
struct stat filestat; struct stat filestat;
int i = 0; int i = 0;
int res;
while(i < 20) while(i < 20)
{ {
res = dirnext(dirIter,filename,&filestat); entry = readdir(dir);
if(res != 0) if(entry == NULL)
break; break;
if(filename[0] == '.' && filename[1] != '.') if(entry->d_name[0] == '.' && entry->d_name[1] != '.')
continue; continue;
ext = GetExt(filename); ext = GetExt(entry->d_name);
stat(entry->d_name,&filestat);
// don't show the file if it's not a valid ROM // don't show the file if it's not a valid ROM
if(parseFilter && (filestat.st_mode & _IFDIR) == 0) if(parseFilter && (filestat.st_mode & _IFDIR) == 0)
@ -520,14 +520,14 @@ bool ParseDirEntries()
break; break;
} }
strncpy(browserList[browser.numEntries+i].filename, filename, MAXJOLIET); strncpy(browserList[browser.numEntries+i].filename, entry->d_name, MAXJOLIET);
browserList[browser.numEntries+i].length = filestat.st_size; browserList[browser.numEntries+i].length = filestat.st_size;
browserList[browser.numEntries+i].mtime = filestat.st_mtime; browserList[browser.numEntries+i].mtime = filestat.st_mtime;
browserList[browser.numEntries+i].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir browserList[browser.numEntries+i].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir
if(browserList[browser.numEntries+i].isdir) if(browserList[browser.numEntries+i].isdir)
{ {
if(strcmp(filename, "..") == 0) if(strcmp(entry->d_name, "..") == 0)
sprintf(browserList[browser.numEntries+i].displayname, "Up One Level"); sprintf(browserList[browser.numEntries+i].displayname, "Up One Level");
else else
strncpy(browserList[browser.numEntries+i].displayname, browserList[browser.numEntries+i].filename, MAXJOLIET); strncpy(browserList[browser.numEntries+i].displayname, browserList[browser.numEntries+i].filename, MAXJOLIET);
@ -546,10 +546,10 @@ bool ParseDirEntries()
browser.numEntries += i; browser.numEntries += i;
if(res != 0 || parseHalt) if(entry == NULL || parseHalt)
{ {
dirclose(dirIter); // close directory closedir(dir); // close directory
dirIter = NULL; dir = NULL;
// try to find and select the last loaded file // try to find and select the last loaded file
if(selectLoadedFile == 1 && parseHalt == 0 && loadedFile[0] != 0 && browser.dir[0] != 0) if(selectLoadedFile == 1 && parseHalt == 0 && loadedFile[0] != 0 && browser.dir[0] != 0)
@ -603,23 +603,23 @@ ParseDirectory(bool waitParse, bool filter)
ResetBrowser(); // reset browser ResetBrowser(); // reset browser
// open the directory // open the directory
while(dirIter == NULL && retry == 1) while(dir == NULL && retry == 1)
{ {
mounted = ChangeInterface(browser.dir, NOTSILENT); mounted = ChangeInterface(browser.dir, NOTSILENT);
if(mounted) if(mounted)
dirIter = diropen(browser.dir); dir = opendir(browser.dir);
else else
return -1; return -1;
if(dirIter == NULL) if(dir == NULL)
{ {
retry = ErrorPromptRetry("Error opening directory!"); retry = ErrorPromptRetry("Error opening directory!");
} }
} }
// if we can't open the dir, try higher levels // if we can't open the dir, try higher levels
if (dirIter == NULL) if (dir == NULL)
{ {
char * devEnd = strrchr(browser.dir, '/'); char * devEnd = strrchr(browser.dir, '/');
@ -632,13 +632,13 @@ ParseDirectory(bool waitParse, bool filter)
break; break;
devEnd[1] = 0; // strip remaining file listing devEnd[1] = 0; // strip remaining file listing
dirIter = diropen(browser.dir); dir = opendir(browser.dir);
if (dirIter) if (dir)
break; break;
} }
} }
if(dirIter == NULL) if(dir == NULL)
return -1; return -1;
if(IsDeviceRoot(browser.dir)) if(IsDeviceRoot(browser.dir))

View File

@ -11,7 +11,7 @@
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/dir.h> #include <dirent.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <mxml.h> #include <mxml.h>
@ -502,7 +502,7 @@ SavePrefs (bool silent)
return false; return false;
sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER); sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER);
DIR_ITER *dir = diropen(filepath); DIR *dir = opendir(filepath);
if (!dir) if (!dir)
{ {
if(mkdir(filepath, 0777) != 0) if(mkdir(filepath, 0777) != 0)
@ -516,7 +516,7 @@ SavePrefs (bool silent)
} }
else else
{ {
dirclose(dir); closedir(dir);
} }
sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME); sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME);
sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER); sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER);
@ -623,17 +623,17 @@ bool LoadPrefs()
// rename snes9x to snes9xgx // rename snes9x to snes9xgx
if(GCSettings.LoadMethod == DEVICE_SD) if(GCSettings.LoadMethod == DEVICE_SD)
{ {
if(ChangeInterface(DEVICE_SD, NOTSILENT) && diropen("sd:/snes9x")) if(ChangeInterface(DEVICE_SD, NOTSILENT) && opendir("sd:/snes9x"))
rename("sd:/snes9x", "sd:/snes9xgx"); rename("sd:/snes9x", "sd:/snes9xgx");
} }
else if(GCSettings.LoadMethod == DEVICE_USB) else if(GCSettings.LoadMethod == DEVICE_USB)
{ {
if(ChangeInterface(DEVICE_USB, NOTSILENT) && diropen("usb:/snes9x")) if(ChangeInterface(DEVICE_USB, NOTSILENT) && opendir("usb:/snes9x"))
rename("usb:/snes9x", "usb:/snes9xgx"); rename("usb:/snes9x", "usb:/snes9xgx");
} }
else if(GCSettings.LoadMethod == DEVICE_SMB) else if(GCSettings.LoadMethod == DEVICE_SMB)
{ {
if(ChangeInterface(DEVICE_SMB, NOTSILENT) && diropen("smb:/snes9x")) if(ChangeInterface(DEVICE_SMB, NOTSILENT) && opendir("smb:/snes9x"))
rename("smb:/snes9x", "smb:/snes9xgx"); rename("smb:/snes9x", "smb:/snes9xgx");
} }