Remove redundant string copy

This commit is contained in:
Arun Prakash Jana 2019-01-22 20:08:28 +05:30
parent 5623cc55bb
commit 71cc0afe30
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 21 additions and 24 deletions

View File

@ -1115,8 +1115,7 @@ static int setfilter(regex_t *regex, char *filter)
len = COLS; len = COLS;
if (len > NAME_MAX) if (len > NAME_MAX)
len = NAME_MAX; len = NAME_MAX;
regerror(r, regex, g_buf, len); mvprintw(LINES - 1, 0, "regex error: %d\n", r);
printmsg(g_buf);
} }
return r; return r;
@ -1636,6 +1635,7 @@ static bool parsebmstr()
static char *get_bm_loc(int key, char *buf) static char *get_bm_loc(int key, char *buf)
{ {
int r; int r;
ssize_t count;
for (r = 0; bookmark[r].key && r < BM_MAX; ++r) { for (r = 0; bookmark[r].key && r < BM_MAX; ++r) {
if (bookmark[r].key == key) { if (bookmark[r].key == key) {
@ -1647,7 +1647,8 @@ static char *get_bm_loc(int key, char *buf)
return NULL; return NULL;
} }
snprintf(buf, PATH_MAX, "%s%s", home, bookmark[r].loc + 1); count = xstrlcpy(buf, home, PATH_MAX);
xstrlcpy(buf + count - 1, bookmark[r].loc + 1, PATH_MAX - count - 1);
} else } else
xstrlcpy(buf, bookmark[r].loc, PATH_MAX); xstrlcpy(buf, bookmark[r].loc, PATH_MAX);
@ -2554,7 +2555,8 @@ static void populate(char *path, char *lastname)
static void redraw(char *path) static void redraw(char *path)
{ {
static char buf[NAME_MAX + 65] __attribute__ ((aligned)); static char c;
static char buf[12];
static size_t ncols; static size_t ncols;
static int nlines, i, attrs; static int nlines, i, attrs;
static bool mode_changed; static bool mode_changed;
@ -2683,26 +2685,23 @@ static void redraw(char *path)
/* We need to show filename as it may be truncated in directory listing */ /* We need to show filename as it may be truncated in directory listing */
if (!cfg.blkorder) if (!cfg.blkorder)
snprintf(buf, NAME_MAX + 65, "%d/%d %s[%s%s]", mvprintw(LINES - 1, 0, "%d/%d %s[%s%s]\n", cur + 1, ndents, sort,
cur + 1, ndents, sort, unescape(dents[cur].name, NAME_MAX), unescape(dents[cur].name, NAME_MAX),
get_file_sym(dents[cur].mode)); get_file_sym(dents[cur].mode));
else { else {
i = snprintf(buf, 64, "%d/%d ", cur + 1, ndents); xstrlcpy(buf, coolsize(dir_blocks << BLK_SHIFT), 12);
if (cfg.apparentsz) if (cfg.apparentsz)
buf[i++] = 'a'; c = 'a';
else else
buf[i++] = 'd'; c = 'd';
i += snprintf(buf + i, 64, "u: %s (%lu files) ", mvprintw(LINES - 1, 0,
coolsize(dir_blocks << BLK_SHIFT), num_files); "%d/%d %cu: %s (%lu files) vol: %s free [%s%s]\n",
snprintf(buf + i, NAME_MAX, "vol: %s free [%s%s]", cur + 1, ndents, c, buf, num_files,
coolsize(get_fs_info(path, FREE)), coolsize(get_fs_info(path, FREE)),
unescape(dents[cur].name, NAME_MAX), unescape(dents[cur].name, NAME_MAX),
get_file_sym(dents[cur].mode)); get_file_sym(dents[cur].mode));
} }
printmsg(buf);
} else } else
printmsg("0 items"); printmsg("0 items");
} }
@ -3043,7 +3042,8 @@ nochange:
if (cfg.curctx == r) { if (cfg.curctx == r) {
if (sel == SEL_CYCLE) { if (sel == SEL_CYCLE) {
(r == CTX_MAX - 1) ? (r = 0) : ++r; (r == CTX_MAX - 1) ? (r = 0) : ++r;
snprintf(newpath, PATH_MAX, "Create context %d? ('Enter' confirms)", r + 1); snprintf(newpath, PATH_MAX,
"Create context %d? (Enter)", r + 1);
fd = get_input(newpath); fd = get_input(newpath);
if (fd != '\r') if (fd != '\r')
continue; continue;
@ -3348,9 +3348,8 @@ nochange:
dents[r].name, newpath))) dents[r].name, newpath)))
goto nochange; goto nochange;
snprintf(newpath, PATH_MAX, "%d files copied", mvprintw(LINES - 1, 0, "%d files copied\n",
copyendid - copystartid + 1); copyendid - copystartid + 1);
printmsg(newpath);
} }
} }
@ -3359,10 +3358,8 @@ nochange:
if (copier) if (copier)
spawn(copier, NULL, NULL, NULL, F_NOTRACE); spawn(copier, NULL, NULL, NULL, F_NOTRACE);
if (ncp) { /* Some files cherry picked */ if (ncp) /* Some files cherry picked */
snprintf(newpath, PATH_MAX, "%d files copied", ncp); mvprintw(LINES - 1, 0, "%d files copied\n", ncp);
printmsg(newpath);
}
} else } else
printmsg("selection off"); printmsg("selection off");
goto nochange; goto nochange;