summaryrefslogtreecommitdiffstats
path: root/lib/libedit/history.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libedit/history.c')
-rw-r--r--lib/libedit/history.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index 8f30a05..cd86977 100644
--- a/lib/libedit/history.c
+++ b/lib/libedit/history.c
@@ -103,6 +103,7 @@ private int history_getunique(History *, HistEvent *);
private int history_set_fun(History *, History *);
private int history_load(History *, const char *);
private int history_save(History *, const char *);
+private int history_save_fp(History *, FILE*);
private int history_prev_event(History *, HistEvent *, int);
private int history_next_event(History *, HistEvent *, int);
private int history_next_string(History *, HistEvent *, const char *);
@@ -773,22 +774,16 @@ done:
return (i);
}
-
-/* history_save():
- * History save function
+/* history_save_fp():
+ * History save with open FILE*
*/
-private int
-history_save(History *h, const char *fname)
+private int history_save_fp(History *h, FILE* fp)
{
- FILE *fp;
HistEvent ev;
int i = -1, retval;
size_t len, max_size;
char *ptr;
- if ((fp = fopen(fname, "w")) == NULL)
- return (-1);
-
if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
goto done;
if (fputs(hist_cookie, fp) == EOF)
@@ -816,6 +811,26 @@ history_save(History *h, const char *fname)
oomem:
h_free((ptr_t)ptr);
done:
+ return (i);
+
+}
+
+
+/* history_save():
+ * History save function
+ */
+private int
+history_save(History *h, const char *fname)
+{
+ FILE *fp;
+ int i;
+
+ if ((fp = fopen(fname, "w")) == NULL)
+ return (-1);
+
+ i = history_save_fp(h, fp);
+
+done:
(void) fclose(fp);
return (i);
}
@@ -1001,6 +1016,12 @@ history(History *h, HistEvent *ev, int fun, ...)
he_seterrev(ev, _HE_HIST_WRITE);
break;
+ case H_SAVE_FP:
+ retval = history_save_fp(h, va_arg(va, FILE*));
+ if (retval == -1)
+ he_seterrev(ev, _HE_HIST_WRITE);
+ break;
+
case H_PREV_EVENT:
retval = history_prev_event(h, ev, va_arg(va, int));
break;
OpenPOWER on IntegriCloud