nnn

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit eae60c3048086cd8545ac426d35bbc3c5d914de6
parent 20e0c492928360e21e4a7862540526a7960ecdc9
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date:   Tue, 22 Jun 2021 20:27:07 +0530

Simplify mkpath()

Diffstat:
Msrc/nnn.c | 25+++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/nnn.c b/src/nnn.c @@ -910,12 +910,11 @@ static void max_openfds(void) { struct rlimit rl; - if (!getrlimit(RLIMIT_NOFILE, &rl)) { + if (!getrlimit(RLIMIT_NOFILE, &rl)) if (rl.rlim_cur < rl.rlim_max) { rl.rlim_cur = rl.rlim_max; setrlimit(RLIMIT_NOFILE, &rl); } - } } #endif @@ -1036,7 +1035,7 @@ static char *xbasename(char *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); } @@ -1091,19 +1090,17 @@ static inline bool getutil(char *util) */ 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); - - /* Handle root case */ - if (istopdir(dir)) - len = 1; - else - len = xstrsncpy(out, dir, PATH_MAX); + if (name[0] != '/') { // NOLINT + /* Handle root case */ + if (istopdir(dir)) + len = 1; + else + len = xstrsncpy(out, dir, PATH_MAX); - out[len - 1] = '/'; // NOLINT + out[len - 1] = '/'; // NOLINT + } return (xstrsncpy(out + len, name, PATH_MAX - len) + len); }