mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 04:21:24 +08:00
Fix error return value from read_history() and write_history()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
81840c0f84
commit
deb2884310
@ -1603,39 +1603,38 @@ 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)
|
||||||
H.Size = 0;
|
return EOF;
|
||||||
while (H.Size < el_hist_size) {
|
|
||||||
if (!fgets(buf, SCREEN_INC, fp))
|
|
||||||
break;
|
|
||||||
|
|
||||||
buf[strlen(buf) - 1] = 0; /* Remove '\n' */
|
H.Size = 0;
|
||||||
add_history(buf);
|
while (H.Size < el_hist_size) {
|
||||||
}
|
if (!fgets(buf, SCREEN_INC, fp))
|
||||||
|
break;
|
||||||
|
|
||||||
return fclose(fp);
|
buf[strlen(buf) - 1] = 0; /* Remove '\n' */
|
||||||
|
add_history(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return errno;
|
return fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
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++]);
|
||||||
|
|
||||||
return fclose(fp);
|
return fclose(fp);
|
||||||
}
|
|
||||||
|
|
||||||
return errno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user