Replace system with execlp and fix indentation

This commit is contained in:
Night Kaly 2024-11-06 15:11:32 +00:00
parent d67e01086c
commit 462ce7b792
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM

15
ccc.c
View file

@ -173,7 +173,7 @@ int main(int argc, char **argv)
/* go back */
case BACKSPACE:
case ARROW_LEFT:
case 'h':;
case 'h':
/* get parent directory */
strcpy(p_cwd, cwd);
char *last_slash = strrchr(cwd, '/');
@ -1002,8 +1002,19 @@ void edit_file(void)
char command[length];
snprintf(command, length, "%s %s", editor, filename);
system(command);
pid_t pid = fork();
if (pid == 0) {
/* Child process */
execlp(editor, editor, filename, NULL);
_exit(1); /* Exit if exec fails */
} else if (pid > 0) {
/* Parent process */
waitpid(pid, NULL, 0);
list_files();
} else {
/* Fork failed */
wpprintw("fork failed: %s", strerror(errno));
}
}
}