Skip to content

Commit

Permalink
Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 23, 2002
1 parent 70a42ae commit 5b55a52
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 81 deletions.
2 changes: 1 addition & 1 deletion platform/beos.cpp
Expand Up @@ -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);
Expand Down
35 changes: 6 additions & 29 deletions platform/macclassic.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */


Expand Down Expand Up @@ -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);
Expand Down
31 changes: 3 additions & 28 deletions platform/posix.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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)
Expand Down
25 changes: 2 additions & 23 deletions platform/win32.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5b55a52

Please sign in to comment.