Reduce use of malloc

This commit is contained in:
Night Kaly 2024-11-17 19:30:14 +00:00
parent 5e2cb884c5
commit 1e00b18cb5
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM

10
ccc.c
View file

@ -82,9 +82,9 @@ unsigned int focus = 0;
long sel_file = 0;
int file_picker = 1;
int to_open_file = 0;
char *argv_cp;
char cwd[4096];
char p_cwd[4096]; /* previous cwd */
char argv_cp[PATH_MAX];
char cwd[PATH_MAX];
char p_cwd[PATH_MAX]; /* previous cwd */
int half_width;
ArrayList *files;
ArrayList *marked;
@ -115,7 +115,7 @@ int main(int argc, char **argv)
perror("ccc");
die("Error from chdir");
} else if (S_ISREG(st.st_mode)) {
argv_cp = estrdup(argv[1]);
strcpy(argv_cp, argv[1]);
char *last_slash = strrchr(argv_cp, '/');
if (last_slash) {
*last_slash = '\0';
@ -432,8 +432,6 @@ void handle_sigwinch(int ignore)
void cleanup(void)
{
if (argv_cp)
free(argv_cp);
if (files->length != 0) {
arraylist_free(files);
}