aboutsummaryrefslogtreecommitdiffstats
path: root/src/nnn.c
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-04-12 17:44:29 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-04-12 17:44:29 +0530
commit806b91b60d2184346c65613f76b29cd6f2b2d33f (patch)
treecd4d8627a46c1ea1e708a627dab9203a49027a9f /src/nnn.c
parent2b3214bd582f4cd923b4ad9ec876008345aeeabc (diff)
downloadnnn-806b91b60d2184346c65613f76b29cd6f2b2d33f.tar.gz
Simplified dirname()
Diffstat (limited to 'src/nnn.c')
-rw-r--r--src/nnn.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 0ac2da7..397358d 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1084,6 +1084,19 @@ static char *abspath(const char *path, const char *cwd)
return resolved_path;
}
+/* A very simplified implementation, changes path */
+static char *xdirname(char *path)
+{
+ char *base = xmemrchr((uchar *)path, '/', strlen(path));
+
+ if (base == path)
+ path[1] = '\0';
+ else
+ *base = '\0';
+
+ return path;
+}
+
static char *xbasename(char *path)
{
char *base = xmemrchr((uchar *)path, '/', strlen(path)); // NOLINT
@@ -3705,13 +3718,13 @@ static char *visit_parent(char *path, char *newpath, int *presel)
return NULL;
}
- /* Use a copy as dirname() may change the string passed */
+ /* Use a copy as xdirname() may change the string passed */
if (newpath)
xstrsncpy(newpath, path, PATH_MAX);
else
newpath = path;
- dir = dirname(newpath);
+ dir = xdirname(newpath);
if (access(dir, R_OK) == -1) {
printwarn(presel);
return NULL;
@@ -3950,7 +3963,7 @@ static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
if (tmp && strcmp(cfgdir, currentpath) == 0) {
mkpath(cfgdir, tmp, newpath);
child = lstat(newpath, &sb) != -1;
- parent = lstat(dirname(newpath), &psb) != -1;
+ parent = lstat(xdirname(newpath), &psb) != -1;
if (!child && !parent) {
*presel = MSGWAIT;
return FALSE;
@@ -6486,7 +6499,7 @@ static char *load_input()
DPRINTF_S(paths[i]);
xstrsncpy(g_buf, paths[i], PATH_MAX);
- if (!common_prefix(dirname(g_buf), prefixpath)) {
+ if (!common_prefix(xdirname(g_buf), prefixpath)) {
entries = i + 1; // free from the current entry
goto malloc_2;
}