Fixed bug with handling of . and .. that was trashing the heap. Fixed soname of libgc...
[tpg/acess2.git] / Kernel / vfs / open.c
index f827473..2fc27d6 100644 (file)
@@ -61,7 +61,13 @@ char *VFS_GetAbsPath(char *Path)
                }
                strcpy(ret, Path);
        } else {
-               cwdLen = strlen(cwd);
+               if(cwd == NULL) {
+                       cwd = "/";
+                       cwdLen = 1;
+               }
+               else {
+                       cwdLen = strlen(cwd);
+               }
                endLen = cwdLen + pathLen + 2;
                // Prepend the current directory
                ret = malloc(endLen);
@@ -83,17 +89,22 @@ char *VFS_GetAbsPath(char *Path)
                if(pos - read <= 2)
                {
                        // Current Dir "."
-                       if(strncmp(&ret[read], ".", pos-read) == 0)     continue;
+                       if(strncmp(&ret[read], ".", pos-read) == 0) {
+                               ret[write] = '\0';
+                               continue;
+                       }
                        // Parent ".."
                        if(strncmp(&ret[read], "..", pos-read) == 0)
                        {
                                // If there is no higher, silently ignore
                                if(slashNum < 1) {
                                        write = 1;
+                                       ret[1] = '\0';
                                        continue;
                                }
                                // Reverse write pointer
                                write = slashOffsets[ --slashNum ];
+                               ret[write] = '\0';
                                continue;
                        }
                }
@@ -121,7 +132,7 @@ char *VFS_GetAbsPath(char *Path)
        
        // `ret` should now be the absolute path
        LEAVE('s', ret);
-       Log("VFS_GetAbsPath: RETURN '%s'", ret);
+       //Log("VFS_GetAbsPath: RETURN '%s'", ret);
        return ret;
 }
 
@@ -534,7 +545,8 @@ int VFS_ChDir(char *New)
        VFS_Close(fd);
        
        // Free old working directory
-       if( CFGPTR(CFG_VFS_CWD) )       free( CFGPTR(CFG_VFS_CWD) );
+       if( CFGPTR(CFG_VFS_CWD) )
+               free( CFGPTR(CFG_VFS_CWD) );
        // Set new
        CFGPTR(CFG_VFS_CWD) = buf;
        

UCC git Repository :: git.ucc.asn.au