}
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);
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;
}
}
// `ret` should now be the absolute path
LEAVE('s', ret);
- Log("VFS_GetAbsPath: RETURN '%s'", ret);
+ //Log("VFS_GetAbsPath: RETURN '%s'", ret);
return ret;
}
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;