diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2020-04-25 01:28:01 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2020-04-25 03:42:34 +0530 |
commit | 06fe7d52ddfd83b7b70badb228d2683048b2ac4c (patch) | |
tree | d2c1d559bf4acb6a4ce424b3fbdc886ea423a516 | |
parent | f8a243ea913991171e755e014c182719ff1266e0 (diff) | |
download | nnn-06fe7d52ddfd83b7b70badb228d2683048b2ac4c.tar.gz |
Minor refactor
-rw-r--r-- | src/nnn.c | 36 |
1 files changed, 14 insertions, 22 deletions
@@ -1142,8 +1142,8 @@ static size_t seltofile(int fd, uint *pcount, bool tgt) { uint lastpos, count = 0; char *pbuf = pselbuf; - size_t pos = 0, len; - ssize_t r, prefixlen, initlen, tgtlen; + size_t pos = 0; + ssize_t len, prefixlen, initlen; if (pcount) *pcount = 0; @@ -1154,33 +1154,25 @@ static size_t seltofile(int fd, uint *pcount, bool tgt) lastpos = selbufpos - 1; if (tgt) { - prefixlen = (ssize_t)xstrsncpy(g_buf, prefixpath, PATH_MAX) - 1; - initlen = strlen(initpath); + prefixlen = (ssize_t)xstrlen(prefixpath); + initlen = (ssize_t)xstrlen(initpath); } while (pos <= lastpos) { - len = xstrlen(pbuf); - pos += len; + DPRINTF_S(pbuf); + len = (ssize_t)xstrlen(pbuf); - if (!tgt) { - r = write(fd, pbuf, len); - if (r != (ssize_t)len) + if (!tgt || (strncmp(initpath, pbuf, initlen) != 0)) { + if (write(fd, pbuf, len) != len) return pos; } else { - if (!strncmp(initpath, pbuf, initlen)) { - tgtlen = xstrsncpy(g_buf + prefixlen, pbuf + initlen, PATH_MAX - prefixlen - 1); - tgtlen += prefixlen - 1; - } else - tgtlen = (ssize_t)xstrsncpy(g_buf, pbuf, PATH_MAX) - 1; - - r = write(fd, g_buf, tgtlen); - if (r != tgtlen) { - DPRINTF_S(pbuf); - DPRINTF_S(g_buf); - return 0; - } + if (write(fd, prefixpath, prefixlen) != prefixlen) + return pos; + if (write(fd, pbuf + initlen, len - initlen) != (len - initlen)) + return pos; } + pos += len; if (pos <= lastpos) { if (write(fd, "\n", 1) != 1) return pos; @@ -5382,7 +5374,7 @@ nochange: if (cfg.useeditor && (!sb.st_size || #ifdef FILE_MIME_OPTS (get_output(g_buf, CMD_LEN_MAX, "file", FILE_MIME_OPTS, newpath, FALSE) - && !strncmp(g_buf, "text/", 5)))) { + && !(((int *)g_buf)[0] == *(int *)"text" && g_buf[4] == '/')))) { #else /* no mime option; guess from description instead */ (get_output(g_buf, CMD_LEN_MAX, "file", "-b", newpath, FALSE) |