Changed enumeration code to use __PHYSFS_addToLinkedStringList().
authorRyan C. Gordon <icculus@icculus.org>
Tue, 23 Jul 2002 07:46:36 +0000
changeset 362 ac8c846a0a66
parent 361 0f945e89d537
child 363 79f155a51527
Changed enumeration code to use __PHYSFS_addToLinkedStringList().
platform/beos.cpp
platform/macclassic.c
platform/posix.c
platform/win32.c
--- a/platform/beos.cpp	Mon Jul 22 12:08:56 2002 +0000
+++ b/platform/beos.cpp	Tue Jul 23 07:46:36 2002 +0000
@@ -228,7 +228,7 @@
 
     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);
--- a/platform/macclassic.c	Mon Jul 22 12:08:56 2002 +0000
+++ b/platform/macclassic.c	Tue Jul 23 07:46:36 2002 +0000
@@ -303,9 +303,9 @@
         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 @@
 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 @@
             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 @@
     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);
--- a/platform/posix.c	Mon Jul 22 12:08:56 2002 +0000
+++ b/platform/posix.c	Tue Jul 23 07:46:36 2002 +0000
@@ -218,9 +218,7 @@
 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 @@
         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 @@
                 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)
--- a/platform/win32.c	Mon Jul 22 12:08:56 2002 +0000
+++ b/platform/win32.c	Tue Jul 23 07:46:36 2002 +0000
@@ -424,9 +424,7 @@
 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 @@
         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);