aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2014-05-11 01:44:11 +0000
committerEitan Adler <eadler@FreeBSD.org>2014-05-11 01:44:11 +0000
commit8be8ad916f178c4bf1487a6807450ccf77f2430f (patch)
treec8f3a2d1c51f38ed843a43045ed9d4fded7f0814 /lib
parentbdf49e3953150f231b92467c34cade2a318596ba (diff)
downloadsrc-8be8ad916f178c4bf1487a6807450ccf77f2430f.tar.gz
src-8be8ad916f178c4bf1487a6807450ccf77f2430f.zip
libedit: add H_SAVE_FP which saves history to a file pointer.
H_SAVE_FP is similar to H_SAVE but operates on a FILE* instead of a filename. This is useful when operating in capability mode. Reviewed by: christos@NetBSD.org, pfg
Notes
Notes: svn path=/head/; revision=265863
Diffstat (limited to 'lib')
-rw-r--r--lib/libedit/editline.33
-rw-r--r--lib/libedit/hist.h1
-rw-r--r--lib/libedit/histedit.h1
-rw-r--r--lib/libedit/history.c39
4 files changed, 35 insertions, 9 deletions
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3
index 33f7666f4283..df7cd8791803 100644
--- a/lib/libedit/editline.3
+++ b/lib/libedit/editline.3
@@ -682,6 +682,9 @@ Load the history list stored in
.It Dv H_SAVE , Fa "const char *file"
Save the history list to
.Fa file .
+.It Dv H_SAVE_FP , Fa "FILE*"
+Save the history list to the opened
+.Fa FILE* .
.It Dv H_SETUNIQUE , Fa "int unique"
Set flag that adjacent identical event strings should not be entered
into the history.
diff --git a/lib/libedit/hist.h b/lib/libedit/hist.h
index 4f2824aff200..4ddedcc59b3d 100644
--- a/lib/libedit/hist.h
+++ b/lib/libedit/hist.h
@@ -65,6 +65,7 @@ typedef struct el_history_t {
#define HIST_SET(el, num) HIST_FUN(el, H_SET, num)
#define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
+#define HIST_SAVE_FP(el, fp) HIST_FUN(el, H_SAVE_FP fp)
protected int hist_init(EditLine *);
protected void hist_end(EditLine *);
diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h
index 8a6caf96c035..9059ea20e52e 100644
--- a/lib/libedit/histedit.h
+++ b/lib/libedit/histedit.h
@@ -208,6 +208,7 @@ int history(History *, HistEvent *, int, ...);
#define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */
#define H_DELDATA 24 /* , int, histdata_t *);*/
#define H_REPLACE 25 /* , const char *, histdata_t); */
+#define H_SAVE_FP 26 /* , FILE*); */
/*
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index 8f30a05a9973..cd8697724f1d 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;