replace file calls with standard ones

This commit is contained in:
dborth 2011-01-20 02:53:27 +00:00
parent a3b33715bd
commit c5c6e7be1e
2 changed files with 24 additions and 24 deletions

View File

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

View File

@ -11,7 +11,7 @@
#include <gccore.h>
#include <stdio.h>
#include <string.h>
#include <sys/dir.h>
#include <dirent.h>
#include <ogcsys.h>
#include <mxml.h>
@ -670,7 +670,7 @@ SavePrefs (bool silent)
sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER);
DIR_ITER *dir = diropen(filepath);
DIR *dir = opendir(filepath);
if (!dir)
{
if(mkdir(filepath, 0777) != 0)
@ -684,7 +684,7 @@ SavePrefs (bool silent)
}
else
{
dirclose(dir);
closedir(dir);
}
sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME);
sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER);