src/physfs_platform_posix.c
changeset 1559 aaee2b83291f
parent 1543 210b82b60730
child 1581 ad04b99afb88
--- a/src/physfs_platform_posix.c	Fri Aug 11 01:45:29 2017 -0400
+++ b/src/physfs_platform_posix.c	Sat Aug 12 02:19:22 2017 -0400
@@ -118,36 +118,35 @@
 } /* __PHYSFS_platformCalcUserDir */
 
 
-void __PHYSFS_platformEnumerateFiles(const char *dirname,
-                                     PHYSFS_EnumFilesCallback callback,
-                                     const char *origdir,
-                                     void *callbackdata)
+int __PHYSFS_platformEnumerate(const char *dirname,
+                               PHYSFS_EnumerateCallback callback,
+                               const char *origdir, void *callbackdata)
 {
     DIR *dir;
     struct dirent *ent;
-    char *buf = NULL;
+    int retval = 1;
 
-    errno = 0;
     dir = opendir(dirname);
-    if (dir == NULL)
+    BAIL_IF(dir == NULL, errcodeFromErrno(), -1);
+
+    while ((retval == 1) && ((ent = readdir(dir)) != NULL))
     {
-        allocator.Free(buf);
-        return;
-    } /* if */
+        const char *name = ent->d_name;
+        if (name[0] == '.')  /* ignore "." and ".." */
+        {
+            if ((name[1] == '\0') || ((name[1] == '.') && (name[2] == '\0')))
+                continue;
+        } /* if */
 
-    while ((ent = readdir(dir)) != NULL)
-    {
-        if (strcmp(ent->d_name, ".") == 0)
-            continue;
-        else if (strcmp(ent->d_name, "..") == 0)
-            continue;
-
-        callback(callbackdata, origdir, ent->d_name);
+        retval = callback(callbackdata, origdir, name);
+        if (retval == -1)
+            PHYSFS_setErrorCode(PHYSFS_ERR_APP_CALLBACK);
     } /* while */
 
-    allocator.Free(buf);
     closedir(dir);
-} /* __PHYSFS_platformEnumerateFiles */
+
+    return retval;
+} /* __PHYSFS_platformEnumerate */
 
 
 int __PHYSFS_platformMkDir(const char *path)