mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
cli: Fix ast_el_read_char to work with libedit >= 3.1
Libedit 3.1 is not build with unicode on as a default and so the prototype for the el_gets callback changed from expecting a char buffer to accepting a wchar buffer. If ast_el_read_char isn't changed, the cli reads garbage from teh terminal. Added a configure test for (*el_rfunc_t)(EditLine *, wchar_t *) and updated ast_el_read_char to use the HAVE_ define to detemrine whether to use char or wchar. ASTERISK-26592 #close Change-Id: I9099b46f68e06d0202ff80e53022a2b68b08871a
This commit is contained in:
@@ -2691,7 +2691,11 @@ static void send_rasterisk_connect_commands(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBEDIT_IS_UNICODE
|
||||
static int ast_el_read_char(EditLine *editline, wchar_t *cp)
|
||||
#else
|
||||
static int ast_el_read_char(EditLine *editline, char *cp)
|
||||
#endif
|
||||
{
|
||||
int num_read = 0;
|
||||
int lastpos = 0;
|
||||
@@ -2721,10 +2725,16 @@ static int ast_el_read_char(EditLine *editline, char *cp)
|
||||
}
|
||||
|
||||
if (!ast_opt_exec && fds[1].revents) {
|
||||
num_read = read(STDIN_FILENO, cp, 1);
|
||||
char c = '\0';
|
||||
num_read = read(STDIN_FILENO, &c, 1);
|
||||
if (num_read < 1) {
|
||||
break;
|
||||
} else {
|
||||
#ifdef HAVE_LIBEDIT_IS_UNICODE
|
||||
*cp = btowc(c);
|
||||
#else
|
||||
*cp = c;
|
||||
#endif
|
||||
return (num_read);
|
||||
}
|
||||
}
|
||||
@@ -2768,7 +2778,11 @@ static int ast_el_read_char(EditLine *editline, char *cp)
|
||||
console_print(buf);
|
||||
|
||||
if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (res >= 2 && buf[res-2] == '\n'))) {
|
||||
#ifdef HAVE_LIBEDIT_IS_UNICODE
|
||||
*cp = btowc(CC_REFRESH);
|
||||
#else
|
||||
*cp = CC_REFRESH;
|
||||
#endif
|
||||
return(1);
|
||||
} else {
|
||||
lastpos = 1;
|
||||
@@ -2776,7 +2790,12 @@ static int ast_el_read_char(EditLine *editline, char *cp)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBEDIT_IS_UNICODE
|
||||
*cp = btowc('\0');
|
||||
#else
|
||||
*cp = '\0';
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user