Skip to content

Commit ae8a84d

Browse files
committed
Settings_new() code shrink
No need to temporarily duplicate the XDG_CONFIG_HOME path string. Note that I didn't simplify or leave out the allocation of "$XDG_CONFIG_HOME/htop" or "$HOME/.config/htop" string because I suspect this string might be reused in the future. Signed-off-by: Kang-Che Sung <[email protected]>
1 parent 7cc12ba commit ae8a84d

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Settings.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ int Settings_write(const Settings* this, bool onCrash) {
685685
return 0;
686686
} else {
687687
// Prepare temp filename
688-
xAsprintf(&tmpFilename, "%s.tmp.XXXXXX", this->filename);
688+
tmpFilename = String_cat(this->filename, ".tmp.XXXXXX");
689689

690690
// Create ancestor directories with mode 0700
691691
mode_t cur_umask = umask(S_IRWXG | S_IRWXO);
@@ -881,19 +881,14 @@ Settings* Settings_new(const Machine* host, Hashtable* dynamicMeters, Hashtable*
881881
home = (pw && pw->pw_dir && pw->pw_dir[0] == '/') ? pw->pw_dir : "";
882882
}
883883
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
884-
char* configDir = NULL;
885884
char* htopDir = NULL;
886885
if (xdgConfigHome && xdgConfigHome[0] == '/') {
887-
this->initialFilename = String_cat(xdgConfigHome, "/htop/htoprc");
888-
configDir = xStrdup(xdgConfigHome);
889886
htopDir = String_cat(xdgConfigHome, "/htop");
890887
} else {
891-
this->initialFilename = String_cat(home, CONFIGDIR "/htop/htoprc");
892-
configDir = String_cat(home, CONFIGDIR);
893888
htopDir = String_cat(home, CONFIGDIR "/htop");
894889
}
890+
this->initialFilename = String_cat(htopDir, "/htoprc");
895891
free(htopDir);
896-
free(configDir);
897892

898893
legacyDotfile = String_cat(home, "/.htoprc");
899894
}

0 commit comments

Comments
 (0)