cex

C/Curses file EXplorer
git clone git://git.wimdupont.com/cex.git
Log | Files | Refs | README | LICENSE

commit fa9721fc35ae7afa230f86ed6fbb10ba6c12a4f1
parent 722b5b5a8ad5624adae64d7ee057343501a8c71a
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat,  4 Apr 2026 21:22:50 +0200

redraw optimization

Diffstat:
Mcex.c | 21++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/cex.c b/cex.c @@ -30,6 +30,7 @@ typedef struct _win_file { char d_name[256]; unsigned char d_type; bool selected; + bool link_valid; } WinFile; typedef struct _dir_win { @@ -454,6 +455,7 @@ set_win_files(DirWin *dirwin) { struct dirent *ent; size_t count = 0, cap = 16; + char linkpath[PATH_MAX]; DIR *dir; free_dirwin(dirwin); @@ -487,7 +489,13 @@ set_win_files(DirWin *dirwin) cpstr(dirwin->winfiles[count].d_name, ent->d_name); dirwin->winfiles[count].d_type = ent->d_type; dirwin->winfiles[count].selected = is_selected(dirwin, count); - (count)++; + if (ent->d_type == DT_LNK) { + get_fullpath(linkpath, dirwin, count); + dirwin->winfiles[count].link_valid = (linkpath[0] != '\0' + && access(linkpath, F_OK) == 0); + } else + dirwin->winfiles[count].link_valid = TRUE; + count++; } closedir(dir); @@ -560,7 +568,7 @@ print_win(DirWin *dirwin) return; size_t cplen, size = dirwin->maxx; - char *subs, name[size+1], sbuf[size+1], pathbuf[PATH_MAX]; + char *subs, name[size+1], sbuf[size+1]; int sindex, y = 0, x = 1; werase(dirwin->window); @@ -611,7 +619,7 @@ print_win(DirWin *dirwin) wattroff(dirwin->window, COLOR_PAIR(DIR_COLOR)); wattroff(dirwin->window, A_BOLD); } else if (dirwin->winfiles[i].d_type == DT_LNK) { - if (access(get_fullpath(pathbuf, dirwin, i), F_OK) == 0) { + if (dirwin->winfiles[i].link_valid) { wattron(dirwin->window, COLOR_PAIR(LN_COLOR)); mvwaddstr(dirwin->window, y, x, name); wattroff(dirwin->window, COLOR_PAIR(LN_COLOR)); @@ -1777,13 +1785,12 @@ get_fullpath(char *buf, DirWin *dirwin, size_t index) { index = MIN(index, dirwin->filecount-1); index = MAX(index, 0); - size_t len; if (strcmp(dirwin->path, "/") == 0) snprintf(buf, PATH_MAX, "/%s", dirwin->winfiles[index].d_name); - else { - len = PATH_MAX + arrlen(dirwin->winfiles[index].d_name); - snprintf(buf, len, "%s/%s", dirwin->path, dirwin->winfiles[index].d_name); + else if (snprintf(buf, PATH_MAX, "%s/%s", dirwin->path, + dirwin->winfiles[index].d_name) >= PATH_MAX) { + buf[0] = '\0'; } return buf;