summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2016-05-08 13:52:33 +0000
committerschwarze <schwarze@openbsd.org>2016-05-08 13:52:33 +0000
commit42bbcabc56f4764ca1e1ca8f6478ab1dac345d4d (patch)
treebec7ed053b9f10e7daeac6909ee837543823af04
parentMake the history_set_pos() return values agree with the GNU implementation. (diff)
downloadwireguard-openbsd-42bbcabc56f4764ca1e1ca8f6478ab1dac345d4d.tar.xz
wireguard-openbsd-42bbcabc56f4764ca1e1ca8f6478ab1dac345d4d.zip
Change where_history() to agree with the GNU implementation:
Return 0 for the oldest entry and increment by 1 for each newer, non-deleted entry. This fixes the test_where() regression test. Patch from Bastian Maerkisch <bmaerkisch at web dot de>. OK czarkoff@.
-rw-r--r--lib/libedit/readline.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c
index 51901891582..0675b16a705 100644
--- a/lib/libedit/readline.c
+++ b/lib/libedit/readline.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readline.c,v 1.22 2016/05/08 13:34:35 schwarze Exp $ */
+/* $OpenBSD: readline.c,v 1.23 2016/05/08 13:52:33 schwarze Exp $ */
/* $NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $ */
/*-
@@ -1487,9 +1487,12 @@ where_history(void)
return 0;
curr_num = ev.num;
- (void)history(h, &ev, H_FIRST);
- off = 1;
- while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0)
+ /* start from the oldest */
+ (void)history(h, &ev, H_LAST);
+
+ /* position is zero-based */
+ off = 0;
+ while (ev.num != curr_num && history(h, &ev, H_PREV) == 0)
off++;
return off;