1
1

history: take into account that closing a file can fail

Этот коммит содержится в:
Benno Schulenberg 2020-06-29 13:05:10 +02:00
родитель 3344571227
Коммит 675a8e4899

Просмотреть файл

@ -293,10 +293,10 @@ void load_history(void)
UNSET(HISTORYLOG); UNSET(HISTORYLOG);
} }
free(histname); if (histfile == NULL) {
free(histname);
if (histfile == NULL)
return; return;
}
linestruct **history = &search_history; linestruct **history = &search_history;
char *line = NULL; char *line = NULL;
@ -316,7 +316,10 @@ void load_history(void)
history = &execute_history; history = &execute_history;
} }
fclose(histfile); if (fclose(histfile) == EOF)
jot_error(N_("Error reading %s: %s"), histname, strerror(errno));
free(histname);
free(line); free(line);
/* Reading in the lists has marked them as changed; undo this side effect. */ /* Reading in the lists has marked them as changed; undo this side effect. */
@ -366,12 +369,12 @@ void save_history(void)
/* Don't allow others to read or write the history file. */ /* Don't allow others to read or write the history file. */
chmod(histname, S_IRUSR | S_IWUSR); chmod(histname, S_IRUSR | S_IWUSR);
if (!write_list(searchtop, histfile) || if (!write_list(searchtop, histfile) || !write_list(replacetop, histfile) ||
!write_list(replacetop, histfile) || !write_list(executetop, histfile))
!write_list(executetop, histfile))
jot_error(N_("Error writing %s: %s\n"), histname, strerror(errno)); jot_error(N_("Error writing %s: %s\n"), histname, strerror(errno));
fclose(histfile); if (fclose(histfile) == EOF)
jot_error(N_("Error writing %s: %s\n"), histname, strerror(errno));
free(histname); free(histname);
} }
@ -438,7 +441,9 @@ void load_poshistory(void)
} }
} }
fclose(histfile); if (fclose(histfile) == EOF)
jot_error(N_("Error reading %s: %s"), poshistname, strerror(errno));
free(line); free(line);
stat(poshistname, &stat_of_positions_file); stat(poshistname, &stat_of_positions_file);
@ -480,7 +485,8 @@ void save_poshistory(void)
free(path_and_place); free(path_and_place);
} }
fclose(histfile); if (fclose(histfile) == EOF)
jot_error(N_("Error writing %s: %s\n"), poshistname, strerror(errno));
stat(poshistname, &stat_of_positions_file); stat(poshistname, &stat_of_positions_file);
} }