Changed enumeration code to use __PHYSFS_addToLinkedStringList().
This commit is contained in:
parent
70a42aeadd
commit
5b55a52af7
|
@ -228,7 +228,7 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
|
|
||||||
BPath normalized(str, leaf, true); /* force normalization of path. */
|
BPath normalized(str, leaf, true); /* force normalization of path. */
|
||||||
const char *resolved_path = normalized.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);
|
char *retval = (char *) malloc(strlen(resolved_path) + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
strcpy(retval, resolved_path);
|
strcpy(retval, resolved_path);
|
||||||
|
|
|
@ -303,9 +303,9 @@ static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
|
||||||
char *path = alloca(strlen(fname) + 1);
|
char *path = alloca(strlen(fname) + 1);
|
||||||
strcpy(path, fname);
|
strcpy(path, fname);
|
||||||
ptr = strchr(path, ':');
|
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, ':');
|
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';
|
*ptr = '\0';
|
||||||
err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
|
err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
|
||||||
BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
|
BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
|
||||||
|
@ -458,9 +458,7 @@ void __PHYSFS_platformTimeslice(void)
|
||||||
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
int omitSymLinks)
|
int omitSymLinks)
|
||||||
{
|
{
|
||||||
LinkedStringList *retval = NULL;
|
LinkedStringList *ret = NULL, *p = NULL;
|
||||||
LinkedStringList *l = NULL;
|
|
||||||
LinkedStringList *prev = NULL;
|
|
||||||
UInt16 i;
|
UInt16 i;
|
||||||
UInt16 max;
|
UInt16 max;
|
||||||
FSSpec spec;
|
FSSpec spec;
|
||||||
|
@ -509,31 +507,10 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* still here? Add it to the list. */
|
/* still here? Add it to the list. */
|
||||||
|
ret = __PHYSFS_addToLinkedStringList(ret, &p, &str255[1], str255[0]);
|
||||||
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;
|
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
return(retval);
|
return(ret);
|
||||||
} /* __PHYSFS_platformEnumerateFiles */
|
} /* __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);
|
BAIL_IF_MACRO((err != noErr) && (err != fnfErr), ERR_OS_ERROR, NULL);
|
||||||
if (err == fnfErr)
|
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,
|
err = HCreate(spec.vRefNum, spec.parID, spec.name,
|
||||||
procInfo.processSignature, 'BINA');
|
procInfo.processSignature, 'BINA');
|
||||||
BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
|
BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
|
||||||
|
|
|
@ -218,9 +218,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
||||||
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
int omitSymLinks)
|
int omitSymLinks)
|
||||||
{
|
{
|
||||||
LinkedStringList *retval = NULL;
|
LinkedStringList *retval = NULL, *p = NULL;
|
||||||
LinkedStringList *l = NULL;
|
|
||||||
LinkedStringList *prev = NULL;
|
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
int bufsize = 0;
|
int bufsize = 0;
|
||||||
|
@ -250,12 +248,8 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
BAIL_IF_MACRO(1, strerror(errno), NULL);
|
BAIL_IF_MACRO(1, strerror(errno), NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
while (1)
|
while ((ent = readdir(dir)) != NULL)
|
||||||
{
|
{
|
||||||
ent = readdir(dir);
|
|
||||||
if (ent == NULL) /* we're done. */
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (strcmp(ent->d_name, ".") == 0)
|
if (strcmp(ent->d_name, ".") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -280,26 +274,7 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
continue;
|
continue;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
|
retval = __PHYSFS_addToLinkedStringList(retval, &p, ent->d_name, -1);
|
||||||
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;
|
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
|
|
|
@ -424,9 +424,7 @@ void __PHYSFS_platformTimeslice(void)
|
||||||
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
int omitSymLinks)
|
int omitSymLinks)
|
||||||
{
|
{
|
||||||
LinkedStringList *retval = NULL;
|
LinkedStringList *retval = NULL, *p = NULL;
|
||||||
LinkedStringList *l = NULL;
|
|
||||||
LinkedStringList *prev = NULL;
|
|
||||||
HANDLE dir;
|
HANDLE dir;
|
||||||
WIN32_FIND_DATA ent;
|
WIN32_FIND_DATA ent;
|
||||||
char *SearchPath;
|
char *SearchPath;
|
||||||
|
@ -460,26 +458,7 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
if (strcmp(ent.cFileName, "..") == 0)
|
if (strcmp(ent.cFileName, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
|
retval = __PHYSFS_addToLinkedStringList(retval, &p, ent.cFileName, -1);
|
||||||
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;
|
|
||||||
} while (FindNextFile(dir, &ent) != 0);
|
} while (FindNextFile(dir, &ent) != 0);
|
||||||
|
|
||||||
FindClose(dir);
|
FindClose(dir);
|
||||||
|
|
Loading…
Reference in New Issue