git: e7a517bee5a7 - stable/14 - libedit: import vendor snapshot 2025-01-03

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Wed, 30 Apr 2025 08:07:46 UTC
The branch stable/14 has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=e7a517bee5a7c167605ee0ed3cb56586de2a92d0

commit e7a517bee5a7c167605ee0ed3cb56586de2a92d0
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2025-04-16 20:21:05 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2025-04-30 08:07:39 +0000

    libedit: import vendor snapshot 2025-01-03
    
    (cherry picked from commit 136d69caf03bc38de95c4df34c5a683e9ce81bfa)
---
 contrib/libedit/Makefile            |  14 ++-
 contrib/libedit/chared.c            |   6 +-
 contrib/libedit/chartype.c          |  12 +--
 contrib/libedit/common.c            |   7 +-
 contrib/libedit/edit.expsym         | 204 ++++++++++++++++++++++++++++++++++++
 contrib/libedit/editline.3          |   4 +-
 contrib/libedit/editline.7          |   6 +-
 contrib/libedit/el.c                |   5 +-
 contrib/libedit/el.h                |   5 +-
 contrib/libedit/eln.c               |  12 ++-
 contrib/libedit/emacs.c             |  10 +-
 contrib/libedit/filecomplete.c      |   6 +-
 contrib/libedit/filecomplete.h      |   5 +-
 contrib/libedit/history.c           |  13 ++-
 contrib/libedit/keymacro.c          |   8 +-
 contrib/libedit/libedit.pc          |  12 +++
 contrib/libedit/literal.c           |   6 +-
 contrib/libedit/map.c               |   5 +-
 contrib/libedit/read.c              |   5 +-
 contrib/libedit/readline.c          |  24 +++--
 contrib/libedit/readline/readline.h |  38 ++++---
 contrib/libedit/refresh.c           |  14 ++-
 contrib/libedit/search.c            |   7 +-
 contrib/libedit/sig.c               |   6 +-
 contrib/libedit/sys.h               |   4 +-
 contrib/libedit/tokenizer.c         |  10 +-
 26 files changed, 350 insertions(+), 98 deletions(-)

diff --git a/contrib/libedit/Makefile b/contrib/libedit/Makefile
index 105a6a92e0ee..f7cd3baf885f 100644
--- a/contrib/libedit/Makefile
+++ b/contrib/libedit/Makefile
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.66 2019/10/13 07:28:10 mrg Exp $
+#	$NetBSD: Makefile,v 1.70 2023/08/03 14:56:36 rin Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -21,6 +21,12 @@ SRCS =	chared.c chartype.c common.c el.c eln.c emacs.c filecomplete.c \
 
 MAN=	editline.3 editrc.5 editline.7
 
+FILES+=			libedit.pc
+FILESOWN_libedit.pc=	${BINOWN}
+FILESGRP_libedit.pc=	${BINGRP}
+FILESMODE_libedit.pc=	${NONBINMODE}
+FILESDIR_libedit.pc=	/usr/lib/pkgconfig
+
 MLINKS= \
 editline.3 el_deletestr.3 \
 editline.3 el_end.3 \
@@ -138,6 +144,6 @@ COPTS.tokenizer.c+=	-Wno-cast-qual
 COPTS.tokenizern.c+=	-Wno-cast-qual
 .endif
 
-COPTS.history.c+=	${GCC_NO_STRINGOP_OVERFLOW}
-COPTS.historyn.c+=	${GCC_NO_STRINGOP_OVERFLOW}
-COPTS.readline.c+=	${GCC_NO_STRINGOP_TRUNCATION} ${GCC_NO_STRINGOP_OVERFLOW}
+COPTS.history.c+=	${CC_WNO_STRINGOP_OVERFLOW}
+COPTS.historyn.c+=	${CC_WNO_STRINGOP_OVERFLOW}
+COPTS.readline.c+=	${CC_WNO_STRINGOP_TRUNCATION} ${CC_WNO_STRINGOP_OVERFLOW}
diff --git a/contrib/libedit/chared.c b/contrib/libedit/chared.c
index 03d31ddeec85..72d84e46740f 100644
--- a/contrib/libedit/chared.c
+++ b/contrib/libedit/chared.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: chared.c,v 1.63 2022/10/30 19:11:31 christos Exp $	*/
+/*	$NetBSD: chared.c,v 1.64 2024/06/29 14:13:14 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)chared.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: chared.c,v 1.63 2022/10/30 19:11:31 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.64 2024/06/29 14:13:14 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -319,6 +319,8 @@ cv_prev_word(wchar_t *p, wchar_t *low, int n, int (*wtest)(wint_t))
 		test = (*wtest)(*p);
 		while ((p >= low) && (*wtest)(*p) == test)
 			p--;
+		if (p < low)
+			return low;
 	}
 	p++;
 
diff --git a/contrib/libedit/chartype.c b/contrib/libedit/chartype.c
index 9c74cfeb677a..b731d63bafb5 100644
--- a/contrib/libedit/chartype.c
+++ b/contrib/libedit/chartype.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: chartype.c,v 1.36 2022/10/30 19:11:31 christos Exp $	*/
+/*	$NetBSD: chartype.c,v 1.37 2023/08/10 20:38:00 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.36 2022/10/30 19:11:31 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.37 2023/08/10 20:38:00 mrg Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <ctype.h>
@@ -235,17 +235,17 @@ ct_visual_string(const wchar_t *s, ct_buffer_t *conv)
 		}
 
 		/* failed to encode, need more buffer space */
-		used = dst - conv->wbuff;
+		uintptr_t sused = (uintptr_t)dst - (uintptr_t)conv->wbuff;
 		if (ct_conv_wbuff_resize(conv, conv->wsize + CT_BUFSIZ) == -1)
 			return NULL;
-		dst = conv->wbuff + used;
+		dst = conv->wbuff + sused;
 	}
 
 	if (dst >= (conv->wbuff + conv->wsize)) { /* sigh */
-		used = dst - conv->wbuff;
+		uintptr_t sused = (uintptr_t)dst - (uintptr_t)conv->wbuff;
 		if (ct_conv_wbuff_resize(conv, conv->wsize + CT_BUFSIZ) == -1)
 			return NULL;
-		dst = conv->wbuff + used;
+		dst = conv->wbuff + sused;
 	}
 
 	*dst = L'\0';
diff --git a/contrib/libedit/common.c b/contrib/libedit/common.c
index f33c29650d79..e038956464c4 100644
--- a/contrib/libedit/common.c
+++ b/contrib/libedit/common.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp $	*/
+/*	$NetBSD: common.c,v 1.50 2024/06/30 16:29:42 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)common.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp $");
+__RCSID("$NetBSD: common.c,v 1.50 2024/06/30 16:29:42 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -222,7 +222,8 @@ ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__)))
 			return CC_REFRESH;
 		}
 #ifdef VI_MOVE
-		el->el_line.cursor--;
+		if (el->el_line.cursor > el->el_line.buffer)
+			el->el_line.cursor--;
 #endif
 	}
 	return CC_CURSOR;
diff --git a/contrib/libedit/edit.expsym b/contrib/libedit/edit.expsym
new file mode 100644
index 000000000000..c5d021b31a65
--- /dev/null
+++ b/contrib/libedit/edit.expsym
@@ -0,0 +1,204 @@
+_el_fn_complete
+_el_fn_sh_complete
+_rl_abort_internal
+_rl_complete_mark_directories
+_rl_completion_prefix_display_length
+_rl_echoing_p
+_rl_erase_entire_line
+_rl_print_completions_horizontally
+_rl_qsort_string_compare
+add_history
+append_history
+clear_history
+completion_matches
+ct_decode_string
+ct_encode_string
+current_history
+el_beep
+el_cursor
+el_deletestr
+el_deletestr1
+el_end
+el_get
+el_getc
+el_gets
+el_init
+el_init_fd
+el_insertstr
+el_line
+el_parse
+el_push
+el_replacestr
+el_reset
+el_resize
+el_set
+el_source
+el_wget
+el_wgetc
+el_wgets
+el_winsertstr
+el_wline
+el_wparse
+el_wpush
+el_wreplacestr
+el_wset
+emacs_ctlx_keymap
+emacs_meta_keymap
+emacs_standard_keymap
+filename_completion_function
+fn_complete
+fn_complete2
+fn_display_match_list
+fn_filename_completion_function
+fn_tilde_expand
+free_history_entry
+get_history_event
+history
+history_arg_extract
+history_base
+history_end
+history_expand
+history_expansion_char
+history_get
+history_get_history_state
+history_inhibit_expansion_function
+history_init
+history_is_stifled
+history_length
+history_list
+history_max_entries
+history_no_expand_chars
+history_offset
+history_search
+history_search_pos
+history_search_prefix
+history_set_pos
+history_subst_char
+history_tokenize
+history_total_bytes
+history_truncate_file
+history_w
+history_wend
+history_winit
+max_input_history
+next_history
+previous_history
+read_history
+readline
+readline_echoing_p
+remove_history
+replace_history_entry
+rl_abort
+rl_add_defun
+rl_already_prompted
+rl_attempted_completion_function
+rl_attempted_completion_over
+rl_basic_quote_characters
+rl_basic_word_break_characters
+rl_bind_key
+rl_bind_key_in_map
+rl_callback_handler_install
+rl_callback_handler_remove
+rl_callback_read_char
+rl_catch_signals
+rl_catch_sigwinch
+rl_cleanup_after_signal
+rl_complete
+rl_completer_quote_characters
+rl_completer_word_break_characters
+rl_completion_append_character
+rl_completion_display_matches_hook
+rl_completion_entry_function
+rl_completion_matches
+rl_completion_query_items
+rl_completion_suppress_append
+rl_completion_type
+rl_completion_word_break_hook
+rl_copy_text
+rl_crlf
+rl_delete_text
+rl_deprep_term_function
+rl_deprep_terminal
+rl_ding
+rl_directory_completion_hook
+rl_display_match_list
+rl_display_prompt
+rl_done
+rl_echo_signal_char
+rl_end
+rl_erase_empty_line
+rl_event_hook
+rl_filename_completion_desired
+rl_filename_completion_function
+rl_forced_update_display
+rl_free_line_state
+rl_generic_bind
+rl_get_keymap
+rl_get_previous_history
+rl_get_screen_size
+rl_getc_function
+rl_ignore_completion_duplicates
+rl_inhibit_completion
+rl_initialize
+rl_insert
+rl_insert_text
+rl_instream
+rl_kill_text
+rl_library_version
+rl_line_buffer
+rl_linefunc
+rl_make_bare_keymap
+rl_message
+rl_newline
+rl_on_new_line
+rl_outstream
+rl_parse_and_bind
+rl_point
+rl_pre_input_hook
+rl_prep_term_function
+rl_prep_terminal
+rl_prompt
+rl_prompt_saved
+rl_read_init_file
+rl_read_key
+rl_readline_name
+rl_readline_state
+rl_readline_version
+rl_redisplay
+rl_redisplay_function
+rl_replace_line
+rl_reset_after_signal
+rl_reset_terminal
+rl_resize_terminal
+rl_restore_prompt
+rl_save_prompt
+rl_set_key
+rl_set_keyboard_input_timeout
+rl_set_keymap
+rl_set_keymap_name
+rl_set_prompt
+rl_set_screen_size
+rl_sort_completion_matches
+rl_special_prefixes
+rl_startup1_hook
+rl_startup_hook
+rl_stuff_char
+rl_terminal_name
+rl_variable_bind
+stifle_history
+tilde_expand
+tok_end
+tok_init
+tok_line
+tok_reset
+tok_str
+tok_wend
+tok_winit
+tok_wline
+tok_wreset
+tok_wstr
+unstifle_history
+username_completion_function
+using_history
+where_history
+write_history
diff --git a/contrib/libedit/editline.3 b/contrib/libedit/editline.3
index f104dcc07c7a..465af0e655df 100644
--- a/contrib/libedit/editline.3
+++ b/contrib/libedit/editline.3
@@ -1,4 +1,4 @@
-.\"	$NetBSD: editline.3,v 1.101 2021/08/15 10:12:54 wiz Exp $
+.\"	$NetBSD: editline.3,v 1.102 2024/02/04 18:47:27 andvar Exp $
 .\"
 .\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -512,7 +512,7 @@ If the
 .Fa flag
 argument is non-zero, then
 .Nm editline
-attempts to recover from read errors, ignoring the first interrrupted
+attempts to recover from read errors, ignoring the first interrupted
 error, and trying to reset the input file descriptor to reset non-blocking I/O.
 This is disabled by default, and desirable only when
 .Nm editline
diff --git a/contrib/libedit/editline.7 b/contrib/libedit/editline.7
index 863bab96d519..9a96fca47fa5 100644
--- a/contrib/libedit/editline.7
+++ b/contrib/libedit/editline.7
@@ -1,4 +1,4 @@
-.\"	$NetBSD: editline.7,v 1.5 2016/05/09 21:27:55 christos Exp $
+.\"	$NetBSD: editline.7,v 1.6 2024/04/06 13:36:11 christos Exp $
 .\"	$OpenBSD: editline.7,v 1.1 2016/04/20 01:11:45 schwarze Exp $
 .\"
 .\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd May 7, 2016
+.Dd April 6, 2024
 .Dt EDITLINE 7
 .Os
 .Sh NAME
@@ -546,7 +546,7 @@ It is an error if the cursor is already at the end of the edit
 buffer.
 .It Ic em-set-mark Pq emacs: Ctrl-Q, NUL
 Set the mark at the current cursor position.
-.It Ic em-toggle-overwrite Pq not bound by default
+.It Ic em-toggle-overwrite Pq insert
 Switch from insert to overwrite mode or vice versa.
 .It Ic em-universal-argument Pq not bound by default
 If in argument input mode, multiply the argument by 4.
diff --git a/contrib/libedit/el.c b/contrib/libedit/el.c
index 2c06e32de9ff..577fda821870 100644
--- a/contrib/libedit/el.c
+++ b/contrib/libedit/el.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: el.c,v 1.101 2022/10/30 19:11:31 christos Exp $	*/
+/*	$NetBSD: el.c,v 1.102 2025/01/03 00:40:08 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)el.c	8.2 (Berkeley) 1/3/94";
 #else
-__RCSID("$NetBSD: el.c,v 1.101 2022/10/30 19:11:31 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.102 2025/01/03 00:40:08 rillig Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -274,7 +274,6 @@ el_wset(EditLine *el, int op, ...)
 		default:
 			rv = -1;
 			EL_ABORT((el->el_errfile, "Bad op %d\n", op));
-			break;
 		}
 		break;
 	}
diff --git a/contrib/libedit/el.h b/contrib/libedit/el.h
index 757137839eb8..a1e9cea11747 100644
--- a/contrib/libedit/el.h
+++ b/contrib/libedit/el.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: el.h,v 1.46 2021/08/15 10:08:41 christos Exp $	*/
+/*	$NetBSD: el.h,v 1.48 2025/01/03 00:40:08 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -58,6 +58,7 @@
 #define	NARROW_HISTORY	0x040
 #define	NO_RESET	0x080
 #define	FIXIO		0x100
+#define	FROM_ELLINE	0x200
 
 typedef unsigned char el_action_t;	/* Index to command array	*/
 
@@ -152,7 +153,7 @@ libedit_private EditLine *el_init_internal(const char *, FILE *, FILE *,
 					 __FILE__, __LINE__); \
 				fprintf a; \
 				abort(); \
-			} while( /*CONSTCOND*/0);
+			} while (0)
 #else
 #define EL_ABORT(a)	abort()
 #endif
diff --git a/contrib/libedit/eln.c b/contrib/libedit/eln.c
index 563ec2a672a9..660e1988cc26 100644
--- a/contrib/libedit/eln.c
+++ b/contrib/libedit/eln.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: eln.c,v 1.37 2022/01/11 18:30:15 christos Exp $	*/
+/*	$NetBSD: eln.c,v 1.38 2024/05/17 02:59:08 christos Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: eln.c,v 1.37 2022/01/11 18:30:15 christos Exp $");
+__RCSID("$NetBSD: eln.c,v 1.38 2024/05/17 02:59:08 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <errno.h>
@@ -365,6 +365,10 @@ el_line(EditLine *el)
 	size_t offset;
 	const wchar_t *p;
 
+	if (el->el_flags & FROM_ELLINE)
+		return info;
+
+	el->el_flags |= FROM_ELLINE;
 	info->buffer   = ct_encode_string(winfo->buffer, &el->el_lgcyconv);
 
 	offset = 0;
@@ -377,6 +381,10 @@ el_line(EditLine *el)
 		offset += ct_enc_width(*p);
 	info->lastchar = info->buffer + offset;
 
+	if (el->el_chared.c_resizefun)  
+		(*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg);
+	el->el_flags &= ~FROM_ELLINE;
+
 	return info;
 }
 
diff --git a/contrib/libedit/emacs.c b/contrib/libedit/emacs.c
index 0636c28b26fc..19a9cf191168 100644
--- a/contrib/libedit/emacs.c
+++ b/contrib/libedit/emacs.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $	*/
+/*	$NetBSD: emacs.c,v 1.38 2024/06/29 17:28:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)emacs.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $");
+__RCSID("$NetBSD: emacs.c,v 1.38 2024/06/29 17:28:07 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -134,11 +134,11 @@ em_yank(EditLine *el, wint_t c __attribute__((__unused__)))
 		return CC_ERROR;
 
 	el->el_chared.c_kill.mark = el->el_line.cursor;
-	cp = el->el_line.cursor;
 
 	/* open the space, */
 	c_insert(el,
 	    (int)(el->el_chared.c_kill.last - el->el_chared.c_kill.buf));
+	cp = el->el_line.cursor;
 	/* copy the chars */
 	for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
 		*cp++ = *kp;
@@ -448,12 +448,12 @@ em_copy_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
 	if (el->el_line.cursor == el->el_line.buffer)
 		return CC_ERROR;
 
-	oldc = el->el_line.cursor;
 	/* does a bounds check */
 	cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
 	    el->el_state.argument, ce__isword);
 
-	c_insert(el, (int)(oldc - cp));
+	c_insert(el, (int)(el->el_line.cursor - cp));
+	oldc = el->el_line.cursor;
 	for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
 		*dp++ = *cp;
 
diff --git a/contrib/libedit/filecomplete.c b/contrib/libedit/filecomplete.c
index ee017fb406d5..a2001a4be955 100644
--- a/contrib/libedit/filecomplete.c
+++ b/contrib/libedit/filecomplete.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: filecomplete.c,v 1.72 2023/02/03 22:01:42 christos Exp $	*/
+/*	$NetBSD: filecomplete.c,v 1.73 2023/04/25 17:51:32 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.72 2023/02/03 22:01:42 christos Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.73 2023/04/25 17:51:32 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -459,11 +459,11 @@ out:
 		el_free(expname);
 	return rs;
 }
+
 /*
  * returns list of completions for text given
  * non-static for readline.
  */
-char ** completion_matches(const char *, char *(*)(const char *, int));
 char **
 completion_matches(const char *text, char *(*genfunc)(const char *, int))
 {
diff --git a/contrib/libedit/filecomplete.h b/contrib/libedit/filecomplete.h
index 796ae7ab3276..884586c438f7 100644
--- a/contrib/libedit/filecomplete.h
+++ b/contrib/libedit/filecomplete.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: filecomplete.h,v 1.14 2021/09/26 13:45:54 christos Exp $	*/
+/*	$NetBSD: filecomplete.h,v 1.15 2023/04/25 17:51:32 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -48,4 +48,7 @@ void fn_display_match_list(EditLine *, char **, size_t, size_t,
 char *fn_tilde_expand(const char *);
 char *fn_filename_completion_function(const char *, int);
 
+/* XXX: readline */
+char **completion_matches(const char *, char *(*)(const char *, int));
+
 #endif
diff --git a/contrib/libedit/history.c b/contrib/libedit/history.c
index 73cfa6b8ead9..8395b329784d 100644
--- a/contrib/libedit/history.c
+++ b/contrib/libedit/history.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: history.c,v 1.63 2019/10/08 19:17:57 christos Exp $	*/
+/*	$NetBSD: history.c,v 1.64 2024/07/11 05:41:24 kre 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.63 2019/10/08 19:17:57 christos Exp $");
+__RCSID("$NetBSD: history.c,v 1.64 2024/07/11 05:41:24 kre Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -45,6 +45,7 @@ __RCSID("$NetBSD: history.c,v 1.63 2019/10/08 19:17:57 christos Exp $");
  * hist.c: TYPE(History) access functions
  */
 #include <sys/stat.h>
+#include <fcntl.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
@@ -842,8 +843,6 @@ history_save_fp(TYPE(History) *h, size_t nelem, FILE *fp)
 	static ct_buffer_t conv;
 #endif
 
-	if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
-		goto done;
 	if (ftell(fp) == 0 && fputs(hist_cookie, fp) == EOF)
 		goto done;
 	ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
@@ -891,7 +890,11 @@ history_save(TYPE(History) *h, const char *fname)
     FILE *fp;
     int i;
 
-    if ((fp = fopen(fname, "w")) == NULL)
+    if ((i = open(fname, O_WRONLY|O_CREAT|O_TRUNC,
+		S_IRUSR|S_IWUSR)) == -1)
+	return -1;
+
+    if ((fp = fdopen(i, "w")) == NULL)
 	return -1;
 
     i = history_save_fp(h, (size_t)-1, fp);
diff --git a/contrib/libedit/keymacro.c b/contrib/libedit/keymacro.c
index cef24a1752e6..38ae9be58df9 100644
--- a/contrib/libedit/keymacro.c
+++ b/contrib/libedit/keymacro.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: keymacro.c,v 1.24 2019/07/23 10:18:52 christos Exp $	*/
+/*	$NetBSD: keymacro.c,v 1.25 2025/01/03 00:40:08 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)key.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: keymacro.c,v 1.24 2019/07/23 10:18:52 christos Exp $");
+__RCSID("$NetBSD: keymacro.c,v 1.25 2025/01/03 00:40:08 rillig Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -346,7 +346,6 @@ node__try(EditLine *el, keymacro_node_t *ptr, const wchar_t *str,
 		default:
 			EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
 			    ptr->type));
-			break;
 		}
 
 		switch (ptr->type = ntype) {
@@ -359,7 +358,6 @@ node__try(EditLine *el, keymacro_node_t *ptr, const wchar_t *str,
 			break;
 		default:
 			EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
-			break;
 		}
 	} else {
 		/* still more chars to go */
@@ -444,7 +442,6 @@ node__put(EditLine *el, keymacro_node_t *ptr)
 		break;
 	default:
 		EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type));
-		break;
 	}
 	el_free(ptr);
 }
@@ -614,7 +611,6 @@ keymacro_kprint(EditLine *el, const wchar_t *key, keymacro_value_t *val,
 			break;
 		default:
 			EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
-			break;
 		}
 	else
 		(void) fprintf(el->el_outfile, fmt, ct_encode_string(key,
diff --git a/contrib/libedit/libedit.pc b/contrib/libedit/libedit.pc
new file mode 100644
index 000000000000..c08a8ba70b12
--- /dev/null
+++ b/contrib/libedit/libedit.pc
@@ -0,0 +1,12 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: libedit
+Description: command line editor library providing generic line editing, history, and tokenization functions.
+Version: 3.1
+Requires:
+Libs: -Wl,-R${libdir} -L${libdir} -ledit
+Libs.private: -ltermcap 
+Cflags: -I${includedir} -I${includedir}/readline
diff --git a/contrib/libedit/literal.c b/contrib/libedit/literal.c
index f6eac26937e8..f6f63cb3fb06 100644
--- a/contrib/libedit/literal.c
+++ b/contrib/libedit/literal.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: literal.c,v 1.5 2019/07/23 13:10:11 christos Exp $	*/
+/*	$NetBSD: literal.c,v 1.6 2024/12/05 22:21:53 christos Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: literal.c,v 1.5 2019/07/23 13:10:11 christos Exp $");
+__RCSID("$NetBSD: literal.c,v 1.6 2024/12/05 22:21:53 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 /*
@@ -85,7 +85,7 @@ literal_add(EditLine *el, const wchar_t *buf, const wchar_t *end, int *wp)
 	w = wcwidth(end[1]);	/* column width of the visible char */
 	*wp = (int)w;
 
-	if (w <= 0)		/* we require something to be printed */
+	if (w < 0)		/* non-printable characters are negative */
 		return 0;
 
 	len = (size_t)(end - buf);
diff --git a/contrib/libedit/map.c b/contrib/libedit/map.c
index 57d3038ab2e9..2ac661993baf 100644
--- a/contrib/libedit/map.c
+++ b/contrib/libedit/map.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: map.c,v 1.55 2022/10/30 19:11:31 christos Exp $	*/
+/*	$NetBSD: map.c,v 1.56 2025/01/03 00:40:08 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)map.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: map.c,v 1.55 2022/10/30 19:11:31 christos Exp $");
+__RCSID("$NetBSD: map.c,v 1.56 2025/01/03 00:40:08 rillig Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -1390,7 +1390,6 @@ map_bind(EditLine *el, int argc, const wchar_t **argv)
 	/* coverity[dead_error_begin] */
 	default:
 		EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
-		break;
 	}
 	return 0;
 }
diff --git a/contrib/libedit/read.c b/contrib/libedit/read.c
index 8026ca4a209b..4d068e9f4097 100644
--- a/contrib/libedit/read.c
+++ b/contrib/libedit/read.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: read.c,v 1.108 2022/10/30 19:11:31 christos Exp $	*/
+/*	$NetBSD: read.c,v 1.109 2025/01/03 00:40:08 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)read.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: read.c,v 1.108 2022/10/30 19:11:31 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.109 2025/01/03 00:40:08 rillig Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -265,7 +265,6 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, wchar_t *ch)
 				return -1;
 			default:
 				EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
-				break;
 			}
 		}
 	} while (cmd == ED_SEQUENCE_LEAD_IN);
diff --git a/contrib/libedit/readline.c b/contrib/libedit/readline.c
index ef3abd4b6daa..3b9b6ac6afcb 100644
--- a/contrib/libedit/readline.c
+++ b/contrib/libedit/readline.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: readline.c,v 1.178 2022/12/02 19:23:15 christos Exp $	*/
+/*	$NetBSD: readline.c,v 1.182 2024/03/26 18:02:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.178 2022/12/02 19:23:15 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.182 2024/03/26 18:02:04 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -51,7 +51,9 @@ __RCSID("$NetBSD: readline.c,v 1.178 2022/12/02 19:23:15 christos Exp $");
 #include <unistd.h>
 #include <vis.h>
 
+#define completion_matches xxx_completion_matches
 #include "readline/readline.h"
+#undef completion_matches
 #include "el.h"
 #include "fcns.h"
 #include "filecomplete.h"
@@ -101,7 +103,7 @@ int max_input_history = 0;
 char history_expansion_char = '!';
 char history_subst_char = '^';
 char *history_no_expand_chars = expand_chars;
-Function *history_inhibit_expansion_function = NULL;
+rl_linebuf_func_t *history_inhibit_expansion_function = NULL;
 char *history_arg_extract(int start, int end, const char *str);
 
 int rl_inhibit_completion = 0;
@@ -122,11 +124,11 @@ int rl_filename_completion_desired = 0;
 int rl_ignore_completion_duplicates = 0;
 int readline_echoing_p = 1;
 int _rl_print_completions_horizontally = 0;
-VFunction *rl_redisplay_function = NULL;
+rl_voidfunc_t *rl_redisplay_function = NULL;
 rl_hook_func_t *rl_startup_hook = NULL;
-VFunction *rl_completion_display_matches_hook = NULL;
-VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal;
-VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal;
+rl_compdisp_func_t *rl_completion_display_matches_hook = NULL;
+rl_vintfunc_t *rl_prep_term_function = (rl_vintfunc_t *)rl_prep_terminal;
+rl_voidfunc_t *rl_deprep_term_function = (rl_voidfunc_t *)rl_deprep_terminal;
 KEYMAP_ENTRY_ARRAY emacs_meta_keymap;
 unsigned long rl_readline_state = RL_STATE_NONE;
 int _rl_complete_mark_directories;
@@ -400,7 +402,7 @@ rl_initialize(void)
 	 * Allow the use of the Delete/Insert keys.
 	 */
 	el_set(e, EL_BIND, "\\e[3~", "ed-delete-next-char", NULL);
-	el_set(e, EL_BIND, "\\e[2~", "ed-quoted-insert", NULL);
+	el_set(e, EL_BIND, "\\e[2~", "em-toggle-overwrite", NULL);
 
 	/*
 	 * Ctrl-left-arrow and Ctrl-right-arrow for word moving.
@@ -1978,7 +1980,7 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key)
 	_rl_update_pos();
 
 	/* Just look at how many global variables modify this operation! */
-	return fn_complete(e,
+	return fn_complete2(e,
 	    (rl_compentry_func_t *)rl_completion_entry_function,
 	    rl_attempted_completion_function,
 	    ct_decode_string(rl_basic_word_break_characters, &wbreak_conv),
@@ -1986,7 +1988,7 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key)
 	    _rl_completion_append_character_function,
 	    (size_t)rl_completion_query_items,
 	    &rl_completion_type, &rl_attempted_completion_over,
-	    &rl_point, &rl_end);
+	    &rl_point, &rl_end, 0);
 
 
 }
@@ -2573,7 +2575,7 @@ void
 rl_reset_after_signal(void)
 {
 	if (rl_prep_term_function)
-		(*rl_prep_term_function)();
+		(*rl_prep_term_function)(1);
 }
 
 void
diff --git a/contrib/libedit/readline/readline.h b/contrib/libedit/readline/readline.h
index 2bd0b7e80ab6..03e2d2eb8e1e 100644
--- a/contrib/libedit/readline/readline.h
+++ b/contrib/libedit/readline/readline.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: readline.h,v 1.53 2022/02/19 17:45:02 christos Exp $	*/
+/*	$NetBSD: readline.h,v 1.55 2023/04/25 17:51:32 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -37,12 +37,13 @@
 /* list of readline stuff supported by editline library's readline wrapper */
 
 /* typedefs */
-typedef int	  Function(const char *, int);
-typedef char     *CPFunction(const char *, int);
-typedef void	  VFunction(void);
+typedef int	  rl_linebuf_func_t(const char *, int);
+typedef void	  rl_voidfunc_t(void);
+typedef void	  rl_vintfunc_t(int);
 typedef void	  rl_vcpfunc_t(char *);
 typedef char	**rl_completion_func_t(const char *, int, int);
 typedef char     *rl_compentry_func_t(const char *, int);
+typedef void	  rl_compdisp_func_t(char **, int, int);
 typedef int	  rl_command_func_t(int, int);
 typedef int	  rl_hook_func_t(void);
 typedef int       rl_icppfunc_t(char **);
@@ -64,7 +65,7 @@ typedef struct _keymap_entry {
 #define ISFUNC	0
 #define ISKMAP	1
 #define ISMACR	2
-	Function *function;
+	rl_linebuf_func_t *function;
 } KEYMAP_ENTRY;
 
 #define KEYMAP_SIZE	256
@@ -111,9 +112,7 @@ extern const char	*rl_readline_name;
 extern FILE		*rl_instream;
 extern FILE		*rl_outstream;
 extern char		*rl_line_buffer;
-extern int		 rl_point, rl_end;
-extern int		 history_base, history_length;
-extern int		 max_input_history;
+extern int		rl_point, rl_end;
 extern const char	*rl_basic_quote_characters;
 extern const char	*rl_basic_word_break_characters;
 extern char		*rl_completer_word_break_characters;
@@ -127,12 +126,23 @@ extern int		rl_completion_query_items;
 extern const char	*rl_special_prefixes;
 extern int		rl_completion_append_character;
 extern int		rl_inhibit_completion;
-extern rl_hook_func_t		*rl_pre_input_hook;
-extern rl_hook_func_t		*rl_startup_hook;
+extern rl_hook_func_t	*rl_pre_input_hook;
+extern rl_hook_func_t	*rl_startup_hook;
 extern char		*rl_terminal_name;
 extern int		rl_already_prompted;
 extern char		*rl_prompt;
 extern int		rl_done;
+extern rl_vcpfunc_t	*rl_linefunc;
+extern rl_hook_func_t   *rl_startup1_hook;
+extern char             *rl_prompt_saved;
+extern int		history_base, history_length;
+extern int		history_offset;
+extern char		history_expansion_char;
+extern char		history_subst_char;
+extern char		*history_no_expand_chars;
+extern rl_linebuf_func_t *history_inhibit_expansion_function;
+extern int		max_input_history;
+
 /*
  * The following is not implemented
  */
@@ -145,10 +155,10 @@ extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
*** 193 LINES SKIPPED ***