Use 'goto fail' to remove code duplication
This commit is contained in:
24
history.c
24
history.c
@@ -65,26 +65,24 @@ saveHistory(Hist *hist, size_t size)
|
|||||||
if (hist == NULL || hist->list == NULL)
|
if (hist == NULL || hist->list == NULL)
|
||||||
return;
|
return;
|
||||||
tmpf = tmpfname(TMPF_HIST, NULL)->ptr;
|
tmpf = tmpfname(TMPF_HIST, NULL)->ptr;
|
||||||
if ((f = fopen(tmpf, "w")) == NULL) {
|
if ((f = fopen(tmpf, "w")) == NULL)
|
||||||
/* FIXME: gettextize? */
|
goto fail;
|
||||||
disp_err_message("Can't open history", FALSE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (item = hist->list->first; item && hist->list->nitem > size;
|
for (item = hist->list->first; item && hist->list->nitem > size;
|
||||||
item = item->next)
|
item = item->next)
|
||||||
size++;
|
size++;
|
||||||
for (; item; item = item->next)
|
for (; item; item = item->next)
|
||||||
fprintf(f, "%s\n", (char *)item->ptr);
|
fprintf(f, "%s\n", (char *)item->ptr);
|
||||||
if (fclose(f) == EOF) {
|
if (fclose(f) == EOF)
|
||||||
/* FIXME: gettextize? */
|
goto fail;
|
||||||
disp_err_message("Can't save history", FALSE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
rename_ret = rename(tmpf, rcFile(HISTORY_FILE));
|
rename_ret = rename(tmpf, rcFile(HISTORY_FILE));
|
||||||
if (rename_ret != 0) {
|
if (rename_ret != 0)
|
||||||
disp_err_message("Can't save history", FALSE);
|
goto fail;
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
disp_err_message("Can't open history", FALSE);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif /* USE_HISTORY */
|
#endif /* USE_HISTORY */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user