tweaks: rename one variable once more

So that it is not a substring of some other name.
master
Benno Schulenberg 2017-09-17 21:37:52 +02:00
parent 09ab91c79c
commit fd86696658
1 changed files with 23 additions and 22 deletions

View File

@ -293,7 +293,7 @@ void load_history(void)
char *histname = histfilename(); char *histname = histfilename();
char *legacyhist = legacyhistfilename(); char *legacyhist = legacyhistfilename();
struct stat hstat; struct stat hstat;
FILE *histfile; FILE *hisfile;
/* If there is an old history file, migrate it. */ /* If there is an old history file, migrate it. */
/* (To be removed in 2018.) */ /* (To be removed in 2018.) */
@ -308,9 +308,9 @@ void load_history(void)
legacyhist, histname); legacyhist, histname);
} }
histfile = fopen(histname, "rb"); hisfile = fopen(histname, "rb");
if (histfile == NULL) { if (hisfile == NULL) {
if (errno != ENOENT) { if (errno != ENOENT) {
/* When reading failed, don't save history when we quit. */ /* When reading failed, don't save history when we quit. */
UNSET(HISTORYLOG); UNSET(HISTORYLOG);
@ -326,7 +326,7 @@ void load_history(void)
size_t buf_len = 0; size_t buf_len = 0;
ssize_t read; ssize_t read;
while ((read = getline(&line, &buf_len, histfile)) > 0) { while ((read = getline(&line, &buf_len, hisfile)) > 0) {
line[--read] = '\0'; line[--read] = '\0';
if (read > 0) { if (read > 0) {
/* Encode any embedded NUL as 0x0A. */ /* Encode any embedded NUL as 0x0A. */
@ -339,7 +339,7 @@ void load_history(void)
} }
fclose(histfile); fclose(hisfile);
free(line); free(line);
} }
@ -352,7 +352,7 @@ void load_history(void)
/* Write the lines of a history list, starting at head, from oldest to newest, /* Write the lines of a history list, starting at head, from oldest to newest,
* to the given file. Return TRUE if writing succeeded, and FALSE otherwise. */ * to the given file. Return TRUE if writing succeeded, and FALSE otherwise. */
bool write_list(const filestruct *head, FILE *histfile) bool write_list(const filestruct *head, FILE *hisfile)
{ {
const filestruct *item; const filestruct *item;
@ -362,9 +362,9 @@ bool write_list(const filestruct *head, FILE *histfile)
/* Decode 0x0A bytes as embedded NULs. */ /* Decode 0x0A bytes as embedded NULs. */
sunder(item->data); sunder(item->data);
if (fwrite(item->data, sizeof(char), length, histfile) < length) if (fwrite(item->data, sizeof(char), length, hisfile) < length)
return FALSE; return FALSE;
if (putc('\n', histfile) == EOF) if (putc('\n', hisfile) == EOF)
return FALSE; return FALSE;
} }
@ -375,28 +375,29 @@ bool write_list(const filestruct *head, FILE *histfile)
void save_history(void) void save_history(void)
{ {
char *histname; char *histname;
FILE *histfile; FILE *hisfile;
/* If the histories are unchanged, don't bother saving them. */ /* If the histories are unchanged, don't bother saving them. */
if (!history_changed) if (!history_changed)
return; return;
histname = histfilename(); histname = histfilename();
histfile = fopen(histname, "wb"); hisfile = fopen(histname, "wb");
if (histfile == NULL) if (hisfile == NULL)
fprintf(stderr, _("Error writing %s: %s\n"), histname, fprintf(stderr, _("Error writing %s: %s\n"), histname,
strerror(errno)); strerror(errno));
else { else {
/* 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) || !write_list(replacetop, histfile) || if (!write_list(searchtop, hisfile) ||
!write_list(executetop, histfile)) !write_list(replacetop, hisfile) ||
!write_list(executetop, hisfile))
fprintf(stderr, _("Error writing %s: %s\n"), histname, fprintf(stderr, _("Error writing %s: %s\n"), histname,
strerror(errno)); strerror(errno));
fclose(histfile); fclose(hisfile);
} }
free(histname); free(histname);
@ -406,9 +407,9 @@ void save_history(void)
void load_poshistory(void) void load_poshistory(void)
{ {
char *poshist = poshistfilename(); char *poshist = poshistfilename();
FILE *histfile = fopen(poshist, "rb"); FILE *hisfile = fopen(poshist, "rb");
if (histfile == NULL) { if (hisfile == NULL) {
if (errno != ENOENT) { if (errno != ENOENT) {
/* When reading failed, don't save history when we quit. */ /* When reading failed, don't save history when we quit. */
UNSET(POS_HISTORY); UNSET(POS_HISTORY);
@ -421,7 +422,7 @@ void load_poshistory(void)
poshiststruct *record_ptr = NULL, *newrecord; poshiststruct *record_ptr = NULL, *newrecord;
/* Read and parse each line, and store the extracted data. */ /* Read and parse each line, and store the extracted data. */
while ((read = getline(&line, &buf_len, histfile)) > 5) { while ((read = getline(&line, &buf_len, hisfile)) > 5) {
/* Decode nulls as embedded newlines. */ /* Decode nulls as embedded newlines. */
unsunder(line, read); unsunder(line, read);
@ -462,7 +463,7 @@ void load_poshistory(void)
free(drop_record); free(drop_record);
} }
} }
fclose(histfile); fclose(hisfile);
free(line); free(line);
} }
free(poshist); free(poshist);
@ -473,9 +474,9 @@ void save_poshistory(void)
{ {
char *poshist = poshistfilename(); char *poshist = poshistfilename();
poshiststruct *posptr; poshiststruct *posptr;
FILE *histfile = fopen(poshist, "wb"); FILE *hisfile = fopen(poshist, "wb");
if (histfile == NULL) if (hisfile == NULL)
fprintf(stderr, _("Error writing %s: %s\n"), poshist, strerror(errno)); fprintf(stderr, _("Error writing %s: %s\n"), poshist, strerror(errno));
else { else {
/* Don't allow others to read or write the history file. */ /* Don't allow others to read or write the history file. */
@ -497,12 +498,12 @@ void save_poshistory(void)
/* Restore the terminating newline. */ /* Restore the terminating newline. */
path_and_place[length - 1] = '\n'; path_and_place[length - 1] = '\n';
if (fwrite(path_and_place, sizeof(char), length, histfile) < length) if (fwrite(path_and_place, sizeof(char), length, hisfile) < length)
fprintf(stderr, _("Error writing %s: %s\n"), fprintf(stderr, _("Error writing %s: %s\n"),
poshist, strerror(errno)); poshist, strerror(errno));
free(path_and_place); free(path_and_place);
} }
fclose(histfile); fclose(hisfile);
} }
free(poshist); free(poshist);
} }