Fix error return value from read_history() and write_history()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2020-01-05 07:14:58 +01:00
parent 81840c0f84
commit deb2884310

View File

@ -1603,8 +1603,11 @@ int read_history(const char *filename)
char buf[SCREEN_INC]; char buf[SCREEN_INC];
hist_alloc(); hist_alloc();
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (fp) { if (!fp)
return EOF;
H.Size = 0; H.Size = 0;
while (H.Size < el_hist_size) { while (H.Size < el_hist_size) {
if (!fgets(buf, SCREEN_INC, fp)) if (!fgets(buf, SCREEN_INC, fp))
@ -1617,17 +1620,16 @@ int read_history(const char *filename)
return fclose(fp); return fclose(fp);
} }
return errno;
}
int write_history(const char *filename) int write_history(const char *filename)
{ {
FILE *fp; FILE *fp;
int i = 0;
hist_alloc(); hist_alloc();
fp = fopen(filename, "w"); fp = fopen(filename, "w");
if (fp) { if (!fp)
int i = 0; return EOF;
while (i < H.Size) while (i < H.Size)
fprintf(fp, "%s\n", H.Lines[i++]); fprintf(fp, "%s\n", H.Lines[i++]);
@ -1635,9 +1637,6 @@ int write_history(const char *filename)
return fclose(fp); return fclose(fp);
} }
return errno;
}
/* /*
** Move back to the beginning of the current word and return an ** Move back to the beginning of the current word and return an
** allocated copy of it. ** allocated copy of it.