Changed enumeration code to use __PHYSFS_addToLinkedStringList().

This commit is contained in:
Ryan C. Gordon 2002-07-23 07:46:36 +00:00
parent 70a42aeadd
commit 5b55a52af7
4 changed files with 12 additions and 81 deletions

View File

@ -228,7 +228,7 @@ char *__PHYSFS_platformRealPath(const char *path)
BPath normalized(str, leaf, true); /* force normalization of path. */
const char *resolved_path = normalized.Path();
BAIL_IF_MACRO(resolved_path == NULL, ERR_FILE_NOT_FOUND, NULL);
BAIL_IF_MACRO(resolved_path == NULL, ERR_NO_SUCH_FILE, NULL);
char *retval = (char *) malloc(strlen(resolved_path) + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, resolved_path);

View File

@ -303,9 +303,9 @@ static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
char *path = alloca(strlen(fname) + 1);
strcpy(path, fname);
ptr = strchr(path, ':');
BAIL_IF_MACRO(!ptr, ERR_FILE_NOT_FOUND, err); /* just in case */
BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
ptr = strchr(ptr + 1, ':');
BAIL_IF_MACRO(!ptr, ERR_FILE_NOT_FOUND, err); /* just in case */
BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
*ptr = '\0';
err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
@ -458,9 +458,7 @@ void __PHYSFS_platformTimeslice(void)
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks)
{
LinkedStringList *retval = NULL;
LinkedStringList *l = NULL;
LinkedStringList *prev = NULL;
LinkedStringList *ret = NULL, *p = NULL;
UInt16 i;
UInt16 max;
FSSpec spec;
@ -509,31 +507,10 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
continue;
/* still here? Add it to the list. */
l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
if (l == NULL)
break;
l->str = (char *) malloc(str255[0] + 1);
if (l->str == NULL)
{
free(l);
break;
} /* if */
memcpy(l->str, &str255[1], str255[0]);
l->str[str255[0]] = '\0';
if (retval == NULL)
retval = l;
else
prev->next = l;
prev = l;
l->next = NULL;
ret = __PHYSFS_addToLinkedStringList(ret, &p, &str255[1], str255[0]);
} /* for */
return(retval);
return(ret);
} /* __PHYSFS_platformEnumerateFiles */
@ -588,7 +565,7 @@ static SInt16 *macDoOpen(const char *fname, SInt8 perm, int createIfMissing)
BAIL_IF_MACRO((err != noErr) && (err != fnfErr), ERR_OS_ERROR, NULL);
if (err == fnfErr)
{
BAIL_IF_MACRO(!createIfMissing, ERR_FILE_NOT_FOUND, NULL);
BAIL_IF_MACRO(!createIfMissing, ERR_NO_SUCH_FILE, NULL);
err = HCreate(spec.vRefNum, spec.parID, spec.name,
procInfo.processSignature, 'BINA');
BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);

View File

@ -218,9 +218,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks)
{
LinkedStringList *retval = NULL;
LinkedStringList *l = NULL;
LinkedStringList *prev = NULL;
LinkedStringList *retval = NULL, *p = NULL;
DIR *dir;
struct dirent *ent;
int bufsize = 0;
@ -250,12 +248,8 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
BAIL_IF_MACRO(1, strerror(errno), NULL);
} /* if */
while (1)
while ((ent = readdir(dir)) != NULL)
{
ent = readdir(dir);
if (ent == NULL) /* we're done. */
break;
if (strcmp(ent->d_name, ".") == 0)
continue;
@ -280,26 +274,7 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
continue;
} /* if */
l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
if (l == NULL)
break;
l->str = (char *) malloc(strlen(ent->d_name) + 1);
if (l->str == NULL)
{
free(l);
break;
} /* if */
strcpy(l->str, ent->d_name);
if (retval == NULL)
retval = l;
else
prev->next = l;
prev = l;
l->next = NULL;
retval = __PHYSFS_addToLinkedStringList(retval, &p, ent->d_name, -1);
} /* while */
if (buf != NULL)

View File

@ -424,9 +424,7 @@ void __PHYSFS_platformTimeslice(void)
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks)
{
LinkedStringList *retval = NULL;
LinkedStringList *l = NULL;
LinkedStringList *prev = NULL;
LinkedStringList *retval = NULL, *p = NULL;
HANDLE dir;
WIN32_FIND_DATA ent;
char *SearchPath;
@ -460,26 +458,7 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
if (strcmp(ent.cFileName, "..") == 0)
continue;
l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
if (l == NULL)
break;
l->str = (char *) malloc(strlen(ent.cFileName) + 1);
if (l->str == NULL)
{
free(l);
break;
} /* if */
strcpy(l->str, ent.cFileName);
if (retval == NULL)
retval = l;
else
prev->next = l;
prev = l;
l->next = NULL;
retval = __PHYSFS_addToLinkedStringList(retval, &p, ent.cFileName, -1);
} while (FindNextFile(dir, &ent) != 0);
FindClose(dir);