From 1e99e9d36405b2a13e9917cc4acc0da8bc2b4d5b Mon Sep 17 00:00:00 2001 From: nova Date: Sat, 15 Nov 2025 22:08:20 +0100 Subject: [PATCH] global_path handling --- main.c | 3 +++ threading.c | 31 ++++++++++++------------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index 7677adc..ff9fe9c 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ unsigned int settings; unsigned int file_modifiers; unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); char *start_path; +char *global_path; time_t *seed; WINDOW *win_t; @@ -91,6 +92,7 @@ int main(){ temp_heigth = terminal_height; } if (status & STATUS_RUN_BACKEND) { + global_path = getcwd(NULL, 0); pthread_cond_signal(&cond_top); pthread_cond_signal(&cond_mid); pthread_cond_signal(&cond_lft); @@ -198,6 +200,7 @@ void init() { #endif ESCDELAY = 10; + global_path = getcwd(NULL, 0); char *start_path = getcwd(NULL, 0); setenv("START_PATH", start_path, 0); free(start_path); diff --git a/threading.c b/threading.c index ddc640d..8a00b16 100644 --- a/threading.c +++ b/threading.c @@ -47,6 +47,7 @@ volatile unsigned long selected_file_current = 0; volatile unsigned long selected_file_last = 0; extern unsigned int terminal_width; extern unsigned int status; +extern char *global_path; unsigned int btm_status; @@ -58,13 +59,14 @@ void *thread_mid(){ pthread_cond_wait(&cond_mid, &mutex_mid); unsigned int local_status = status; - char *path; - if((path=getcwd(NULL, 0)) == NULL) { + if (global_path == NULL) { mid_content = malloc(sizeof(file)); mid_content->file_name = "cannot open directory"; mid_file_count = 1; } else { + char *path = malloc(strlen(global_path)+1); + memcpy(path, global_path, strlen(global_path)+1); if (local_status & STATUS_RELOAD_DIRECTORY) { unsigned long i = 0; @@ -99,8 +101,8 @@ void *thread_mid(){ pthread_cond_signal(&cond_rgt); pthread_cond_signal(&cond_btm); + free(path); } - free(path); pthread_mutex_unlock(&mutex_mid); } pthread_exit(0); @@ -112,12 +114,13 @@ void *thread_lft(){ pthread_cond_wait(&cond_lft, &mutex_lft); unsigned int local_status = status; - char *path; - if((path=getcwd(NULL, 0)) == NULL) { + if (global_path == NULL) { lft_content = malloc(sizeof(file)); lft_content[0].file_name = "cannot open directory"; lft_file_count = 1; } else { + char *path = malloc(strlen(global_path)+1); + memcpy(path, global_path, strlen(global_path)+1); path[strrchr(path, '/')-path] = '\0'; path[0] = '/'; @@ -130,8 +133,8 @@ void *thread_lft(){ get_dir_content(path, &lft_file_count, lft_content); } + free(path); } - free(path); pthread_mutex_unlock(&mutex_lft); } pthread_exit(0); @@ -230,18 +233,16 @@ void *thread_top(){ free(top_buffer); - char *path; - if((path=getcwd(NULL, 0)) == NULL) { + if(global_path == NULL) { top_buffer = malloc(sizeof("cannot open directory")); top_width = sizeof("cannot open directory"); top_buffer = "cannot open directory"; } else { - top_buffer = malloc(strlen(path)+1); - memcpy(top_buffer, path, strlen(path)+1); + top_buffer = malloc(strlen(global_path)+1); + memcpy(top_buffer, global_path, strlen(global_path)+1); top_width = strlen(top_buffer); } - free(path); pthread_mutex_unlock(&mutex_top); } pthread_exit(0); @@ -271,14 +272,6 @@ void *thread_btm(){ pthread_mutex_unlock(&mutex_mid); - if (path != NULL) { - /* sometimes NULL remains, need to do deeper analysis soon */ - free(path); - path = NULL; - } else { - volatile static int debug_thread_btm; - debug_thread_btm++; - } free(ui_btm_right_block); path = getcwd(NULL, 0);