mirror of
https://github.com/jarun/nnn.git
synced 2024-12-01 02:49:44 +00:00
Simplify mkpath()
This commit is contained in:
parent
20e0c49292
commit
eae60c3048
13
src/nnn.c
13
src/nnn.c
|
@ -910,13 +910,12 @@ static void max_openfds(void)
|
||||||
{
|
{
|
||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
|
|
||||||
if (!getrlimit(RLIMIT_NOFILE, &rl)) {
|
if (!getrlimit(RLIMIT_NOFILE, &rl))
|
||||||
if (rl.rlim_cur < rl.rlim_max) {
|
if (rl.rlim_cur < rl.rlim_max) {
|
||||||
rl.rlim_cur = rl.rlim_max;
|
rl.rlim_cur = rl.rlim_max;
|
||||||
setrlimit(RLIMIT_NOFILE, &rl);
|
setrlimit(RLIMIT_NOFILE, &rl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1036,7 +1035,7 @@ static char *xbasename(char *path)
|
||||||
return base ? base + 1 : path;
|
return base ? base + 1 : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *xextension(const char *fname, size_t len)
|
static inline char *xextension(const char *fname, size_t len)
|
||||||
{
|
{
|
||||||
return xmemrchr((uchar_t *)fname, '.', len);
|
return xmemrchr((uchar_t *)fname, '.', len);
|
||||||
}
|
}
|
||||||
|
@ -1091,12 +1090,9 @@ static inline bool getutil(char *util)
|
||||||
*/
|
*/
|
||||||
static size_t mkpath(const char *dir, const char *name, char *out)
|
static size_t mkpath(const char *dir, const char *name, char *out)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len = 0;
|
||||||
|
|
||||||
/* Handle absolute path */
|
|
||||||
if (name[0] == '/') // NOLINT
|
|
||||||
return xstrsncpy(out, name, PATH_MAX);
|
|
||||||
|
|
||||||
|
if (name[0] != '/') { // NOLINT
|
||||||
/* Handle root case */
|
/* Handle root case */
|
||||||
if (istopdir(dir))
|
if (istopdir(dir))
|
||||||
len = 1;
|
len = 1;
|
||||||
|
@ -1104,6 +1100,7 @@ static size_t mkpath(const char *dir, const char *name, char *out)
|
||||||
len = xstrsncpy(out, dir, PATH_MAX);
|
len = xstrsncpy(out, dir, PATH_MAX);
|
||||||
|
|
||||||
out[len - 1] = '/'; // NOLINT
|
out[len - 1] = '/'; // NOLINT
|
||||||
|
}
|
||||||
return (xstrsncpy(out + len, name, PATH_MAX - len) + len);
|
return (xstrsncpy(out + len, name, PATH_MAX - len) + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue