From 21a59780271677e38a87a58dc566deee8a7c8c39 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@telfort.nl> Date: Tue, 15 Aug 2017 18:03:41 +0200 Subject: [PATCH] tweaks: reshuffle some code to harmonize two related functions --- src/files.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/files.c b/src/files.c index a98e90bb..76bdf2e8 100644 --- a/src/files.c +++ b/src/files.c @@ -2860,35 +2860,36 @@ bool writehist(FILE *hist, const filestruct *head) /* Save the search and replace histories to ~/.nano/search_history. */ void save_history(void) { - char *nanohist; + char *searchhist; + FILE *hist; /* Don't save unchanged or empty histories. */ if (!history_has_changed() || (searchbot->lineno == 1 && replacebot->lineno == 1)) return; - nanohist = histfilename(); + searchhist = histfilename(); - if (nanohist != NULL) { - FILE *hist = fopen(nanohist, "wb"); + if (searchhist == NULL) + return; + + hist = fopen(searchhist, "wb"); if (hist == NULL) - fprintf(stderr, _("Error writing %s: %s\n"), nanohist, + fprintf(stderr, _("Error writing %s: %s\n"), searchhist, strerror(errno)); else { - /* Make sure no one else can read from or write to the - * history file. */ - chmod(nanohist, S_IRUSR | S_IWUSR); + /* Don't allow others to read or write the history file. */ + chmod(searchhist, S_IRUSR | S_IWUSR); if (!writehist(hist, searchage) || !writehist(hist, replaceage)) - fprintf(stderr, _("Error writing %s: %s\n"), nanohist, + fprintf(stderr, _("Error writing %s: %s\n"), searchhist, strerror(errno)); fclose(hist); } - free(nanohist); - } + free(searchhist); } /* Save the recorded last file positions to ~/.nano/filepos_history. */ -- GitLab