mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Simplified dirname()
This commit is contained in:
parent
2b3214bd58
commit
806b91b60d
21
src/nnn.c
21
src/nnn.c
|
@ -1084,6 +1084,19 @@ static char *abspath(const char *path, const char *cwd)
|
||||||
return resolved_path;
|
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)
|
static char *xbasename(char *path)
|
||||||
{
|
{
|
||||||
char *base = xmemrchr((uchar *)path, '/', strlen(path)); // NOLINT
|
char *base = xmemrchr((uchar *)path, '/', strlen(path)); // NOLINT
|
||||||
|
@ -3705,13 +3718,13 @@ static char *visit_parent(char *path, char *newpath, int *presel)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use a copy as dirname() may change the string passed */
|
/* Use a copy as xdirname() may change the string passed */
|
||||||
if (newpath)
|
if (newpath)
|
||||||
xstrsncpy(newpath, path, PATH_MAX);
|
xstrsncpy(newpath, path, PATH_MAX);
|
||||||
else
|
else
|
||||||
newpath = path;
|
newpath = path;
|
||||||
|
|
||||||
dir = dirname(newpath);
|
dir = xdirname(newpath);
|
||||||
if (access(dir, R_OK) == -1) {
|
if (access(dir, R_OK) == -1) {
|
||||||
printwarn(presel);
|
printwarn(presel);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3950,7 +3963,7 @@ static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
|
||||||
if (tmp && strcmp(cfgdir, currentpath) == 0) {
|
if (tmp && strcmp(cfgdir, currentpath) == 0) {
|
||||||
mkpath(cfgdir, tmp, newpath);
|
mkpath(cfgdir, tmp, newpath);
|
||||||
child = lstat(newpath, &sb) != -1;
|
child = lstat(newpath, &sb) != -1;
|
||||||
parent = lstat(dirname(newpath), &psb) != -1;
|
parent = lstat(xdirname(newpath), &psb) != -1;
|
||||||
if (!child && !parent) {
|
if (!child && !parent) {
|
||||||
*presel = MSGWAIT;
|
*presel = MSGWAIT;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -6486,7 +6499,7 @@ static char *load_input()
|
||||||
DPRINTF_S(paths[i]);
|
DPRINTF_S(paths[i]);
|
||||||
|
|
||||||
xstrsncpy(g_buf, paths[i], PATH_MAX);
|
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
|
entries = i + 1; // free from the current entry
|
||||||
goto malloc_2;
|
goto malloc_2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue