Fixed bug with handling of . and .. that was trashing the heap. Fixed soname of libgc...
[tpg/acess2.git] / Kernel / vfs / open.c
index 86ae3d3..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);
@@ -79,24 +85,26 @@ char *VFS_GetAbsPath(char *Path)
                if(pos == -1)   pos = endLen;
                else    pos += read;    // Else, Adjust to absolute
                
-               //Log("pos-read = %i", pos-read);
-               
                // Check Length
                if(pos - read <= 2)
                {
-                       //Log("&ret[read] = '%s'", &ret[read]);
                        // 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;
                        }
                }
@@ -104,9 +112,9 @@ char *VFS_GetAbsPath(char *Path)
                
                // Only copy if the positions differ
                if(read != write) {
-                       Log("write = %i, read = %i, pos-read+1 = %i", write, read, pos-read+1);
+                       //Log("write = %i, read = %i, pos-read+1 = %i", write, read, pos-read+1);
                        memcpy( &ret[write], &ret[read], pos-read+1 );
-                       Log("ret = '%s'", ret);
+                       //Log("ret = '%s'", ret);
                }
                
                if(slashNum < MAX_PATH_SLASHES)
@@ -124,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;
 }
 
@@ -537,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