MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / read_char

Function read_char

extern/editline/src/read.c:312–379  ·  view source on GitHub ↗

read_char(): * Read a character from the tty. */

Source from the content-addressed store, hash-verified

310 * Read a character from the tty.
311 */
312private int
313read_char(EditLine *el, Char *cp)
314{
315 ssize_t num_read;
316 int tried = 0;
317 char cbuf[MB_LEN_MAX];
318 size_t cbp = 0;
319 int bytes = 0;
320
321 again:
322 el->el_signal->sig_no = 0;
323 while ((num_read = read(el->el_infd, cbuf + cbp, (size_t)1)) == -1) {
324 int e = errno;
325 switch (el->el_signal->sig_no) {
326 case SIGCONT:
327 FUN(el,set)(el, EL_REFRESH);
328 /*FALLTHROUGH*/
329 case SIGWINCH:
330 sig_set(el);
331 goto again;
332 default:
333 break;
334 }
335 if (!tried && read__fixio(el->el_infd, e) == 0)
336 tried = 1;
337 else {
338 errno = e;
339 *cp = '\0';
340 return -1;
341 }
342 }
343
344 /* Test for EOF */
345 if (num_read == 0) {
346 errno = 0;
347 *cp = '\0';
348 return 0;
349 }
350
351#ifdef WIDECHAR
352 if (el->el_flags & CHARSET_IS_UTF8) {
353 if (!utf8_islead((unsigned char)cbuf[0]))
354 goto again; /* discard the byte we read and try again */
355 ++cbp;
356 if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) {
357 ct_mbtowc_reset;
358 if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */
359 errno = EILSEQ;
360 *cp = '\0';
361 return -1;
362 }
363 goto again;
364 }
365 } else if (isascii((unsigned char)cbuf[0]) ||
366 /* we don't support other multibyte charsets */
367 ++cbp != 1 ||
368 /* Try non-ASCII characters in a 8-bit character set */
369 (bytes = ct_mbtowc(cp, cbuf, cbp)) != 1)

Callers

nothing calls this directly

Calls 3

sig_setFunction · 0.85
read__fixioFunction · 0.85
utf8_isleadFunction · 0.85

Tested by

no test coverage detected