cex

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.wimdupont.com/cex.git
Log | Files | Refs | LICENSE

commit 74656d0325d33f5ed257699185a15b645803fa6e
parent d1ce9afc4b77be5e0949bf48ef9afbdb7fc35520
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat, 13 Jul 2024 20:35:14 +0200

no longer change userinfo on chdir

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

diff --git a/cex.c b/cex.c @@ -20,22 +20,18 @@ #include "cex.h" static DirWin curwin, parwin, childwin; -static struct passwd *userinfo; -static char *editor; +static char *userhome, *username, *editor, **selected, searchq[SEARCHLEN]; static int maxy, maxx; -static bool hide = DEFAULT_HIDE; -static bool print_bot = TRUE; -static char **selected; -static size_t selc; -static char searchq[SEARCHLEN]; -static size_t searchc; +static size_t selc, searchc; +static bool hide = DEFAULT_HIDE, print_bot = TRUE; int main(int argc, char **argv) { + struct passwd userinf; + char filename[PATH_MAX]; int opt; bool writepath = FALSE; - char filename[PATH_MAX]; while ((opt = getopt(argc, argv, "f:")) != -1) { switch (opt) { @@ -49,9 +45,13 @@ main(int argc, char **argv) } } - userinfo = getpwuid(getuid()); + editor = getenv("EDITOR"); + userinf = *getpwuid(getuid()); + username = strdup(userinf.pw_name); + userhome = strdup(userinf.pw_dir); + init_dirwins(); init_screen(); @@ -562,7 +562,7 @@ print_top_title() move(0, 0); clrtoeol(); attron(COLOR_PAIR(TOP_TITLE_COLOR)); - printw("%s:%s/%s", userinfo->pw_name, curwin.path, curwin.winfiles[curwin.highlight].d_name); + printw("%s:%s/%s", username, curwin.path, curwin.winfiles[curwin.highlight].d_name); attroff(COLOR_PAIR(TOP_TITLE_COLOR)); } @@ -748,7 +748,7 @@ combo_go(int key) update_child_win(); break; case KEY_COMBO_GO_HOME: - change_dir(userinfo->pw_dir, OTHER, FALSE); + change_dir(userhome, OTHER, FALSE); break; case KEY_COMBO_GO_ACCESS: change_dir(replace_home(pathbuf, LN_ACCESS_DIR), OTHER, FALSE); @@ -1061,6 +1061,9 @@ clean() wclear(parwin.window); wclear(childwin.window); + free(username); + free(userhome); + clear(); delwin(parwin.window); @@ -1463,8 +1466,8 @@ replace_home(char *buf, char *path) size_t hlen; if ((strstr(path, envv) != NULL)) { - hlen = strlen(userinfo->pw_dir); - memcpy(buf, userinfo->pw_dir, hlen); + hlen = strlen(userhome); + memcpy(buf, userhome, hlen); buf[hlen] = '\0'; strcat(buf, path + strlen(envv)); }