#include "asterisk.h"
#include <histedit.h>
#include "editline_compat.h"
Go to the source code of this file.
◆ editline_read_char()
| int editline_read_char |
( |
EditLine * |
el, |
|
|
wchar_t * |
cp |
|
) |
| |
◆ read_char()
| static int read_char |
( |
EditLine * |
el, |
|
|
wchar_t * |
cp |
|
) |
| |
|
static |
Definition at line 71 of file editline_compat.c.
72{
73 ssize_t num_read;
74#ifdef EDITLINE_ORIG
75
76
77
78 int tried = (
el->el_flags & FIXIO) == 0;
79#endif
80 char cbuf[MB_LEN_MAX];
81 size_t cbp = 0;
82#ifdef EDITLINE_ORIG
83
84
85 int save_errno =
errno;
86#endif
87
88 again:
89#ifdef EDITLINE_ORIG
90
91
92
93
94
95
96
97 el->el_signal->sig_no = 0;
98 while ((num_read = read(
el->el_infd, cbuf + cbp, (
size_t)1)) == -1) {
100 switch (
el->el_signal->sig_no) {
101 case SIGCONT:
102 el_wset(
el, EL_REFRESH);
103
104 case SIGWINCH:
106 goto again;
107 default:
108 break;
109 }
110 if (!tried && read__fixio(
el->el_infd, e) == 0) {
112 tried = 1;
113 } else {
115 *cp = L'\0';
116 return -1;
117 }
118 }
119#else
120 while ((num_read = read(STDIN_FILENO, cbuf + cbp, (size_t)1)) == -1) {
121 *cp = L'\0';
122 return -1;
123 }
124#endif
125
126
127 if (num_read == 0) {
128 *cp = L'\0';
129 return 0;
130 }
131
132 for (;;) {
133 mbstate_t mbs;
134
135 ++cbp;
136
137 memset(&mbs, 0, sizeof(mbs));
138 switch (mbrtowc(cp, cbuf, cbp, &mbs)) {
139 case (size_t)-1:
140 if (cbp > 1) {
141
142
143
144
145 cbuf[0] = cbuf[cbp - 1];
146 cbp = 0;
147 break;
148 } else {
149
150 cbp = 0;
151 goto again;
152 }
153 case (size_t)-2:
154 if (cbp >= MB_LEN_MAX) {
156 *cp = L'\0';
157 return -1;
158 }
159
160 goto again;
161 default:
162
163 return 1;
164 }
165 }
166}
References el, and errno.
Referenced by editline_read_char().