diff options
| -rw-r--r-- | bb.c | 22 | ||||
| -rw-r--r-- | bb.h | 2 |
2 files changed, 17 insertions, 7 deletions
@@ -376,12 +376,12 @@ void* memcheck(void *p) * Prepend `root` to relative paths, replace "~" with $HOME. * The normalized path is stored in `normalized`. */ -void normalize_path(const char *root, const char *path, char *normalized) +char *normalize_path(const char *root, const char *path, char *normalized) { char pbuf[PATH_MAX] = {0}; if (path[0] == '~' && (path[1] == '\0' || path[1] == '/')) { char *home; - if (!(home = getenv("HOME"))) return; + if (!(home = getenv("HOME"))) return NULL; strcpy(pbuf, home); ++path; } else if (path[0] != '/') { @@ -389,8 +389,11 @@ void normalize_path(const char *root, const char *path, char *normalized) if (root[strlen(root)-1] != '/') strcat(pbuf, "/"); } strcat(pbuf, path); - if (realpath(pbuf, normalized) == NULL) + if (realpath(pbuf, normalized) == NULL) { strcpy(normalized, pbuf); // TODO: normalize better? + return NULL; + } + return normalized; } /* @@ -413,12 +416,19 @@ int populate_files(bb_t *bb, const char *path) } else if (strcmp(path, "..") == 0 && strcmp(bb->path, "<selection>") == 0) { if (!bb->prev_path[0]) return -1; strcpy(pbuf, bb->prev_path); - if (chdir(pbuf)) return -1; + if (chdir(pbuf)) { + warn("Could not cd to: \"%s\"", pbuf); + return -1; + } } else { - normalize_path(bb->path, path, pbuf); + if (!normalize_path(bb->path, path, pbuf)) + warn("Could not normalize path: \"%s\"", path); if (pbuf[strlen(pbuf)-1] != '/') strcat(pbuf, "/"); - if (chdir(pbuf)) return -1; + if (chdir(pbuf)) { + warn("Could not cd to: \"%s\"", pbuf); + return -1; + } } if (strcmp(bb->path, "<selection>") != 0) { @@ -206,7 +206,7 @@ static int is_simple_bbcmd(const char *s); static entry_t* load_entry(bb_t *bb, const char *path, int clear_dots); static inline int matches_cmd(const char *str, const char *cmd); static void* memcheck(void *p); -static void normalize_path(const char *root, const char *path, char *pbuf); +static char* normalize_path(const char *root, const char *path, char *pbuf); static int populate_files(bb_t *bb, const char *path); static void print_bindings(int fd); static void run_bbcmd(bb_t *bb, const char *cmd); |
