From c9cbe79a61db59ee30c53a4c0ac8cdb3122f88d8 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Thu, 12 Jan 2023 19:33:19 +0900 Subject: [PATCH] Make tmp_dir if not found --- fm.h | 3 +++ main.c | 6 +++--- proto.h | 1 + rc.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/fm.h b/fm.h index 5391ea9..781a8c4 100644 --- a/fm.h +++ b/fm.h @@ -1138,6 +1138,9 @@ extern int symbol_width0; global int no_rc_dir init(FALSE); global char *rc_dir init(NULL); global char *tmp_dir; +#ifdef HAVE_MKDTEMP +global char *mkd_tmp_dir init(NULL); +#endif global char *config_file init(NULL); #ifdef USE_MOUSE diff --git a/main.c b/main.c index 265f70c..bfe19b9 100644 --- a/main.c +++ b/main.c @@ -6034,9 +6034,9 @@ w3m_exit(int i) WSACleanup(); #endif #ifdef HAVE_MKDTEMP - if (no_rc_dir && tmp_dir != rc_dir) - if (rmdir(tmp_dir) != 0) { - fprintf(stderr, "Can't remove temporary directory (%s)!\n", tmp_dir); + if (mkd_tmp_dir) + if (rmdir(mkd_tmp_dir) != 0) { + fprintf(stderr, "Can't remove temporary directory (%s)!\n", mkd_tmp_dir); exit(1); } #endif diff --git a/proto.h b/proto.h index 8b97ae0..c833e9f 100644 --- a/proto.h +++ b/proto.h @@ -631,6 +631,7 @@ extern Str decodeMIME0(Str orgstr); extern int set_param_option(char *option); extern char *get_param_option(char *name); extern void init_rc(void); +extern void init_tmp(void); extern Buffer *load_option_panel(void); extern void panel_set_option(struct parsed_tagarg *); extern void sync_with_option(void); diff --git a/rc.c b/rc.c index a7257c0..37fb087 100644 --- a/rc.c +++ b/rc.c @@ -1291,6 +1291,7 @@ static void loadSiteconf(void); void sync_with_option(void) { + init_tmp(); if (PagerMax < LINES) PagerMax = LINES; WrapSearch = WrapDefault; @@ -1366,11 +1367,12 @@ init_rc(void) system_charset_str = display_charset_str; #endif + tmp_dir = rc_dir; + if (do_recursive_mkdir(rc_dir) == -1) goto rc_dir_err; no_rc_dir = FALSE; - tmp_dir = rc_dir; if (config_file == NULL) config_file = rcFile(CONFIG_FILE); @@ -1395,17 +1397,51 @@ init_rc(void) rc_dir_err: no_rc_dir = TRUE; + create_option_search_table(); + goto open_rc; +} + +void +init_tmp(void) +{ + int i; + + if (*tmp_dir == '\0') + tmp_dir = rc_dir; + + if (strcmp(tmp_dir, rc_dir) == 0) { + if (no_rc_dir) + goto tmp_dir_err; + return; + } + + tmp_dir = expandPath(tmp_dir); + i = strlen(tmp_dir); + if (i > 1 && tmp_dir[i - 1] == '/') + tmp_dir[i - 1] = '\0'; + if (do_recursive_mkdir(tmp_dir) == -1) + goto tmp_dir_err; + return; + + tmp_dir_err: +#ifdef HAVE_MKDTEMP + if (mkd_tmp_dir) { + tmp_dir = mkd_tmp_dir; + return; + } +#endif if (((tmp_dir = getenv("TMPDIR")) == NULL || *tmp_dir == '\0') && ((tmp_dir = getenv("TMP")) == NULL || *tmp_dir == '\0') && ((tmp_dir = getenv("TEMP")) == NULL || *tmp_dir == '\0')) tmp_dir = "/tmp"; #ifdef HAVE_MKDTEMP tmp_dir = mkdtemp(Strnew_m_charp(tmp_dir, "/w3m-XXXXXX", NULL)->ptr); - if (tmp_dir == NULL) + if (tmp_dir) + mkd_tmp_dir = tmp_dir; + else tmp_dir = rc_dir; #endif - create_option_search_table(); - goto open_rc; + return; }