removal of unnecessary getcwd
This commit is contained in:
@@ -319,16 +319,15 @@ void dir_changed(){
|
|||||||
}
|
}
|
||||||
void change_dir(char *new_path){
|
void change_dir(char *new_path){
|
||||||
|
|
||||||
const char *old_path = global_path;
|
|
||||||
current_linked_dir = list_beginning;
|
current_linked_dir = list_beginning;
|
||||||
while (current_linked_dir->next != NULL) {
|
while (current_linked_dir->next != NULL) {
|
||||||
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
current_linked_dir = current_linked_dir->next;
|
current_linked_dir = current_linked_dir->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
||||||
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,21 +337,22 @@ void change_dir(char *new_path){
|
|||||||
* especially in like 2 years when i even forgot about this possibility */
|
* especially in like 2 years when i even forgot about this possibility */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char *new_path_real = getcwd(NULL, 0);
|
free(global_path);
|
||||||
|
global_path = getcwd(NULL, 0);
|
||||||
|
|
||||||
current_linked_dir = list_beginning;
|
current_linked_dir = list_beginning;
|
||||||
while (current_linked_dir->next != NULL) {
|
while (current_linked_dir->next != NULL) {
|
||||||
if(strcmp(current_linked_dir->path, new_path_real) == 0) {
|
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
current_linked_dir = current_linked_dir->next;
|
current_linked_dir = current_linked_dir->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strcmp(current_linked_dir->path, new_path_real) != 0) {
|
if(strcmp(current_linked_dir->path, global_path) != 0) {
|
||||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||||
current_linked_dir = current_linked_dir->next;
|
current_linked_dir = current_linked_dir->next;
|
||||||
current_linked_dir->path = malloc(strlen(new_path_real)+1);
|
current_linked_dir->path = malloc(strlen(global_path)+1);
|
||||||
memcpy(current_linked_dir->path, new_path_real, strlen(new_path_real)+1);
|
memcpy(current_linked_dir->path, global_path, strlen(global_path)+1);
|
||||||
current_linked_dir->next = NULL;
|
current_linked_dir->next = NULL;
|
||||||
current_linked_dir->index = 0;
|
current_linked_dir->index = 0;
|
||||||
/*TODO(2026-05-25T22:49:30)
|
/*TODO(2026-05-25T22:49:30)
|
||||||
@@ -360,8 +360,6 @@ void change_dir(char *new_path){
|
|||||||
}
|
}
|
||||||
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
|
|
||||||
free(new_path_real);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dir_init(){
|
void dir_init(){
|
||||||
|
|||||||
@@ -88,8 +88,6 @@ int main(){
|
|||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
|
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
free(global_path);
|
|
||||||
global_path = getcwd(NULL, 0);
|
|
||||||
pthread_cond_signal(&cond_mid);
|
pthread_cond_signal(&cond_mid);
|
||||||
pthread_cond_signal(&cond_lft);
|
pthread_cond_signal(&cond_lft);
|
||||||
status &= ~(STATUS_RUN_BACKEND);
|
status &= ~(STATUS_RUN_BACKEND);
|
||||||
|
|||||||
Reference in New Issue
Block a user