diff options
author | Yorhel <git@yorhel.nl> | 2009-04-26 12:55:27 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-04-26 12:55:27 +0200 |
commit | 796d043c0df84fd0cb470c0bda9bacd2d39f9d14 (patch) | |
tree | 31eadf136945ed79453cc82eccf2d23fdca3524e | |
parent | 219ae8a6db531640d82acd17efa6a8b412e42ee0 (diff) |
Fixed bug with opening the root directory
-rw-r--r-- | src/calc.c | 36 |
1 files changed, 28 insertions, 8 deletions
@@ -74,7 +74,9 @@ void calc_enterpath(char *name) { /* removes last component from curpath */ void calc_leavepath() { char *tmp; - if((tmp = strrchr(curpath, '/')) != curpath) + if((tmp = strrchr(curpath, '/')) == NULL) + strcpy(curpath, "/"); + else if(tmp != curpath) tmp[0] = 0; else tmp[1] = 0; @@ -296,9 +298,20 @@ void calc_process() { strcpy(errmsg, "Directory not found"); goto calc_fail; } + /* split into path and last component */ name = strrchr(path, '/'); - *(name++) = 0; + if(name == path) { + if(!path[1]) + name = "."; + else { + name = malloc(strlen(path)); + strcpy(name, path+1); + path[1] = 0; + } + } else + *(name++) = 0; + /* we need to chdir so we can provide relative paths for lstat() and opendir(), * this to prevent creating path names longer than PATH_MAX */ if(path_chdir(path) < 0) { @@ -333,15 +346,20 @@ void calc_process() { curdev = fs.st_dev; /* update curpath */ - if((int)strlen(path)+1 > curpathl) { - curpathl = strlen(path)+1; - curpath = realloc(curpath, curpathl); - } - strcpy(curpath, path); + if(strcmp(name, ".")) { + if((int)strlen(path)+1 > curpathl) { + curpathl = strlen(path)+1; + curpath = realloc(curpath, curpathl); + } + strcpy(curpath, path); + } else + curpath[0] = 0; /* start calculating */ if(!calc_dir(root, name) && !failed) { free(path); + if(!path[1] && strcmp(name, ".")) + free(name); if(root->sub == NULL) { freedir(root); failed = 1; @@ -375,6 +393,8 @@ void calc_process() { } /* something went wrong... */ + if(!path[1] && strcmp(name, ".")) + free(name); free(path); freedir(root); calc_fail: @@ -389,7 +409,7 @@ void calc_init(char *dir, struct dir *org) { failed = anpos = 0; orig = org; if(curpathl == 0) { - curpathl = strlen(dir); + curpathl = strlen(dir)+1; curpath = malloc(curpathl); } else if(curpathl < (int)strlen(dir)+1) { curpathl = strlen(dir)+1; |