summaryrefslogtreecommitdiff
path: root/history.c
diff options
context:
space:
mode:
Diffstat (limited to 'history.c')
-rw-r--r--history.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/history.c b/history.c
index 7e8f5209ca5f..6cd05a475b81 100644
--- a/history.c
+++ b/history.c
@@ -1,4 +1,4 @@
-/* $NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $ */
+/* $NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $");
+__RCSID("$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -105,6 +105,7 @@ private int history_getunique(TYPE(History) *, TYPE(HistEvent) *);
private int history_set_fun(TYPE(History) *, TYPE(History) *);
private int history_load(TYPE(History) *, const char *);
private int history_save(TYPE(History) *, const char *);
+private int history_save_fp(TYPE(History) *, FILE *);
private int history_prev_event(TYPE(History) *, TYPE(HistEvent) *, int);
private int history_next_event(TYPE(History) *, TYPE(HistEvent) *, int);
private int history_next_string(TYPE(History) *, TYPE(HistEvent) *, const Char *);
@@ -784,13 +785,12 @@ done:
}
-/* history_save():
+/* history_save_fp():
* TYPE(History) save function
*/
private int
-history_save(TYPE(History) *h, const char *fname)
+history_save_fp(TYPE(History) *h, FILE *fp)
{
- FILE *fp;
TYPE(HistEvent) ev;
int i = -1, retval;
size_t len, max_size;
@@ -800,9 +800,6 @@ history_save(TYPE(History) *h, const char *fname)
static ct_buffer_t conv;
#endif
- 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)
@@ -831,11 +828,29 @@ history_save(TYPE(History) *h, const char *fname)
oomem:
h_free(ptr);
done:
- (void) fclose(fp);
return i;
}
+/* history_save():
+ * History save function
+ */
+private int
+history_save(TYPE(History) *h, const char *fname)
+{
+ FILE *fp;
+ int i;
+
+ if ((fp = fopen(fname, "w")) == NULL)
+ return -1;
+
+ i = history_save_fp(h, fp);
+
+ (void) fclose(fp);
+ return i;
+}
+
+
/* history_prev_event():
* Find the previous event, with number given
*/
@@ -1016,6 +1031,12 @@ FUNW(history)(TYPE(History) *h, TYPE(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;