platform/unix.c
changeset 39 bc29e1ee7ef6
parent 28 529214f57d1b
child 41 ff60d39d0862
--- a/platform/unix.c	Mon Jul 16 10:32:12 2001 +0000
+++ b/platform/unix.c	Mon Jul 16 14:36:02 2001 +0000
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 #include <pwd.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <dirent.h>
 #include <time.h>
 #include <errno.h>
@@ -303,8 +304,14 @@
         if (ent == NULL)   /* we're done. */
             break;
 
+        if (strcmp(ent->d_name, ".") == 0)
+            continue;
+
+        if (strcmp(ent->d_name, "..") == 0)
+            continue;
+
         l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
-        if (l != NULL)
+        if (l == NULL)
             break;
 
         l->str = (char *) malloc(strlen(ent->d_name) + 1);
@@ -314,6 +321,8 @@
             break;
         } /* if */
 
+        strcpy(l->str, ent->d_name);
+
         if (retval == NULL)
             retval = l;
         else
@@ -337,5 +346,43 @@
 } /* __PHYSFS_platformFileLength */
 
 
+char *__PHYSFS_platformCurrentDir(void)
+{
+    int allocSize = 0;
+    char *retval = NULL;
+    char *ptr;
+
+    do
+    {
+        allocSize += 100;
+        ptr = (char *) realloc(retval, allocSize);
+        if (ptr == NULL)
+        {
+            if (retval != NULL)
+                free(retval);
+            BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
+        } /* if */
+
+        retval = ptr;
+        ptr = getcwd(retval, allocSize);
+    } while (ptr == NULL);
+
+    return(retval);
+} /* __PHYSFS_platformCurrentDir */
+
+
+char *__PHYSFS_platformRealPath(const char *path)
+{
+    char resolved_path[MAXPATHLEN];
+    char *retval = NULL;
+
+    errno = 0;
+    BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL);
+    retval = malloc(strlen(resolved_path) + 1);
+    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
+    strcpy(retval, resolved_path);
+    return(retval);
+} /* __PHYSFS_platformRealPath */
+
 /* end of unix.c ... */