aboutsummaryrefslogtreecommitdiffstats
path: root/noice.c
diff options
context:
space:
mode:
authorlostd <lostd@2f30.org>2014-10-10 13:14:55 +0300
committerlostd <lostd@2f30.org>2014-10-10 13:14:55 +0300
commit327720107565e730a15b8d16351c8c4efd34a471 (patch)
tree555a364dc131eba6e6f0c7b7911a0442d497935d /noice.c
parent61cd0f8041e36757f4a02aa8894309412e35ccff (diff)
downloadnoice-327720107565e730a15b8d16351c8c4efd34a471.tar.gz
Handle the root path case correctly
Diffstat (limited to 'noice.c')
-rw-r--r--noice.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/noice.c b/noice.c
index 4c88701..d03400e 100644
--- a/noice.c
+++ b/noice.c
@@ -374,8 +374,12 @@ begin:
dents[n].name = strdup(dp->d_name);
if (dents[n].name == NULL)
printerr(1, "strdup");
+ /* Handle root case */
+ if (strcmp(path, "/") == 0)
+ asprintf(&name, "/%s", dents[n].name);
+ else
+ asprintf(&name, "%s/%s", path, dents[n].name);
/* Get mode flags */
- asprintf(&name, "%s/%s", path, dents[n].name);
r = lstat(name, &sb);
free(name);
if (r == -1)
@@ -406,7 +410,7 @@ redraw:
erase();
/* Strip trailing slashes */
- for (i = strlen(path) - 1; i > -1; i--)
+ for (i = strlen(path) - 1; i > 0; i--)
if (path[i] == '/')
path[i] = '\0';
else
@@ -420,12 +424,7 @@ redraw:
strlcpy(cwd, path, COLS * sizeof(char));
cwd[COLS - strlen(CWD) - 1] = '\0';
- /* Print cwd. If empty we are on the root. We store it
- * as an empty string so that when we navigate in /mnt
- * is doesn't come up as //mnt. */
- printw(CWD "%s%s\n\n",
- strcmp(cwd, "") == 0 ? "/" : "",
- cwd);
+ printw(CWD "%s\n\n", cwd);
/* Print listing */
odd = ISODD(nlines);
@@ -449,8 +448,8 @@ nochange:
free(filter);
return;
case SEL_BACK:
- /* Handle root case */
- if (strcmp(path, "") == 0) {
+ /* There is no going back */
+ if (strcmp(path, "/") == 0) {
goto nochange;
} else {
dir = dirname(path);
Un proyecto texto-plano.xyz