common: rename getc() to getchar()

The sandbox is built with the SDL2 library with invokes the X11 library
which in turn calls getc(). But getc() in glibc is defined as

    int getc(FILE *)

This does not match our definition.

    int getc(void)

The sandbox crashes when called with parameter -l.

Rename our library symbol getc() to getchar().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Heinrich Schuchardt 2020-10-07 18:11:48 +02:00 committed by Tom Rini
parent 8d5d97cb28
commit c670aeee3d
17 changed files with 58 additions and 58 deletions

View File

@ -57,7 +57,7 @@ static int API_getc(va_list ap)
if ((c = (int *)va_arg(ap, uintptr_t)) == NULL) if ((c = (int *)va_arg(ap, uintptr_t)) == NULL)
return API_EINVAL; return API_EINVAL;
*c = getc(); *c = getchar();
return 0; return 0;
} }

View File

@ -99,7 +99,7 @@ static void bootmenu_autoboot_loop(struct bootmenu_data *menu,
} }
menu->delay = -1; menu->delay = -1;
c = getc(); c = getchar();
switch (c) { switch (c) {
case '\e': case '\e':
@ -141,7 +141,7 @@ static void bootmenu_loop(struct bootmenu_data *menu,
mdelay(10); mdelay(10);
} }
c = getc(); c = getchar();
switch (*esc) { switch (*esc) {
case 0: case 0:

View File

@ -81,7 +81,7 @@ static int do_load_serial(struct cmd_tbl *cmdtp, int flag, int argc,
serial_setbrg(); serial_setbrg();
udelay(50000); udelay(50000);
for (;;) { for (;;) {
if (getc() == '\r') if (getchar() == '\r')
break; break;
} }
} }
@ -102,7 +102,7 @@ static int do_load_serial(struct cmd_tbl *cmdtp, int flag, int argc,
*/ */
for (i=0; i<100; ++i) { for (i=0; i<100; ++i) {
if (tstc()) { if (tstc()) {
(void) getc(); getchar();
} }
udelay(1000); udelay(1000);
} }
@ -124,7 +124,7 @@ static int do_load_serial(struct cmd_tbl *cmdtp, int flag, int argc,
serial_setbrg(); serial_setbrg();
udelay(50000); udelay(50000);
for (;;) { for (;;) {
if (getc() == 0x1B) /* ESC */ if (getchar() == 0x1B) /* ESC */
break; break;
} }
} }
@ -212,7 +212,7 @@ static int read_record(char *buf, ulong len)
--len; /* always leave room for terminating '\0' byte */ --len; /* always leave room for terminating '\0' byte */
for (p=buf; p < buf+len; ++p) { for (p=buf; p < buf+len; ++p) {
c = getc(); /* read character */ c = getchar(); /* read character */
if (do_echo) if (do_echo)
putc(c); /* ... and echo it */ putc(c); /* ... and echo it */
@ -229,7 +229,7 @@ static int read_record(char *buf, ulong len)
} }
/* Check for the console hangup (if any different from serial) */ /* Check for the console hangup (if any different from serial) */
if (gd->jt->getc != getc) { if (gd->jt->getc != getchar) {
if (ctrlc()) { if (ctrlc()) {
return (-1); return (-1);
} }
@ -276,7 +276,7 @@ int do_save_serial(struct cmd_tbl *cmdtp, int flag, int argc,
serial_setbrg(); serial_setbrg();
udelay(50000); udelay(50000);
for (;;) { for (;;) {
if (getc() == '\r') if (getchar() == '\r')
break; break;
} }
} }
@ -288,7 +288,7 @@ int do_save_serial(struct cmd_tbl *cmdtp, int flag, int argc,
printf("## Ready for S-Record upload, press ENTER to proceed ...\n"); printf("## Ready for S-Record upload, press ENTER to proceed ...\n");
for (;;) { for (;;) {
if (getc() == '\r') if (getchar() == '\r')
break; break;
} }
if (save_serial(offset, size)) { if (save_serial(offset, size)) {
@ -305,7 +305,7 @@ int do_save_serial(struct cmd_tbl *cmdtp, int flag, int argc,
serial_setbrg(); serial_setbrg();
udelay(50000); udelay(50000);
for (;;) { for (;;) {
if (getc() == 0x1B) /* ESC */ if (getchar() == 0x1B) /* ESC */
break; break;
} }
} }
@ -459,7 +459,7 @@ static int do_load_serial_bin(struct cmd_tbl *cmdtp, int flag, int argc,
serial_setbrg(); serial_setbrg();
udelay(50000); udelay(50000);
for (;;) { for (;;) {
if (getc() == '\r') if (getchar() == '\r')
break; break;
} }
} }
@ -505,7 +505,7 @@ static int do_load_serial_bin(struct cmd_tbl *cmdtp, int flag, int argc,
serial_setbrg(); serial_setbrg();
udelay(50000); udelay(50000);
for (;;) { for (;;) {
if (getc() == 0x1B) /* ESC */ if (getchar() == 0x1B) /* ESC */
break; break;
} }
} }
@ -528,7 +528,7 @@ static ulong load_serial_bin(ulong offset)
*/ */
for (i=0; i<100; ++i) { for (i=0; i<100; ++i) {
if (tstc()) { if (tstc()) {
(void) getc(); getchar();
} }
udelay(1000); udelay(1000);
} }
@ -831,7 +831,7 @@ static int k_recv(void)
/* get a packet */ /* get a packet */
/* wait for the starting character or ^C */ /* wait for the starting character or ^C */
for (;;) { for (;;) {
switch (getc ()) { switch (getchar()) {
case START_CHAR: /* start packet */ case START_CHAR: /* start packet */
goto START; goto START;
case ETX_CHAR: /* ^C waiting for packet */ case ETX_CHAR: /* ^C waiting for packet */
@ -843,13 +843,13 @@ static int k_recv(void)
START: START:
/* get length of packet */ /* get length of packet */
sum = 0; sum = 0;
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
sum += new_char & 0xff; sum += new_char & 0xff;
length = untochar(new_char); length = untochar(new_char);
/* get sequence number */ /* get sequence number */
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
sum += new_char & 0xff; sum += new_char & 0xff;
@ -876,7 +876,7 @@ START:
/* END NEW CODE */ /* END NEW CODE */
/* get packet type */ /* get packet type */
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
sum += new_char & 0xff; sum += new_char & 0xff;
@ -886,19 +886,19 @@ START:
if (length == -2) { if (length == -2) {
/* (length byte was 0, decremented twice) */ /* (length byte was 0, decremented twice) */
/* get the two length bytes */ /* get the two length bytes */
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
sum += new_char & 0xff; sum += new_char & 0xff;
len_hi = untochar(new_char); len_hi = untochar(new_char);
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
sum += new_char & 0xff; sum += new_char & 0xff;
len_lo = untochar(new_char); len_lo = untochar(new_char);
length = len_hi * 95 + len_lo; length = len_hi * 95 + len_lo;
/* check header checksum */ /* check header checksum */
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f)) if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
@ -908,7 +908,7 @@ START:
} }
/* bring in rest of packet */ /* bring in rest of packet */
while (length > 1) { while (length > 1) {
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
sum += new_char & 0xff; sum += new_char & 0xff;
@ -925,13 +925,13 @@ START:
} }
} }
/* get and validate checksum character */ /* get and validate checksum character */
new_char = getc(); new_char = getchar();
if ((new_char & 0xE0) == 0) if ((new_char & 0xE0) == 0)
goto packet_error; goto packet_error;
if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f)) if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
goto packet_error; goto packet_error;
/* get END_CHAR */ /* get END_CHAR */
new_char = getc(); new_char = getchar();
if (new_char != END_CHAR) { if (new_char != END_CHAR) {
packet_error: packet_error:
/* restore state machines */ /* restore state machines */
@ -955,7 +955,7 @@ START:
static int getcxmodem(void) { static int getcxmodem(void) {
if (tstc()) if (tstc())
return (getc()); return (getchar());
return -1; return -1;
} }
static ulong load_serial_ymodem(ulong offset, int mode) static ulong load_serial_ymodem(ulong offset, int mode)

View File

@ -117,7 +117,7 @@ static int passwd_abort_sha256(uint64_t etime)
return 0; return 0;
} }
presskey[presskey_len++] = getc(); presskey[presskey_len++] = getchar();
/* Calculate sha256 upon each new char */ /* Calculate sha256 upon each new char */
hash_block(algo_name, (const void *)presskey, hash_block(algo_name, (const void *)presskey,
@ -189,12 +189,12 @@ static int passwd_abort_key(uint64_t etime)
do { do {
if (tstc()) { if (tstc()) {
if (presskey_len < presskey_max) { if (presskey_len < presskey_max) {
presskey[presskey_len++] = getc(); presskey[presskey_len++] = getchar();
} else { } else {
for (i = 0; i < presskey_max - 1; i++) for (i = 0; i < presskey_max - 1; i++)
presskey[i] = presskey[i + 1]; presskey[i] = presskey[i + 1];
presskey[i] = getc(); presskey[i] = getchar();
} }
} }
@ -257,7 +257,7 @@ static int abortboot_single_key(int bootdelay)
* Check if key already pressed * Check if key already pressed
*/ */
if (tstc()) { /* we got a key press */ if (tstc()) { /* we got a key press */
(void) getc(); /* consume input */ getchar(); /* consume input */
puts("\b\b\b 0"); puts("\b\b\b 0");
abort = 1; /* don't auto boot */ abort = 1; /* don't auto boot */
} }
@ -272,7 +272,7 @@ static int abortboot_single_key(int bootdelay)
abort = 1; /* don't auto boot */ abort = 1; /* don't auto boot */
bootdelay = 0; /* no more delay */ bootdelay = 0; /* no more delay */
key = getc(); /* consume input */ key = getchar();/* consume input */
if (IS_ENABLED(CONFIG_USE_AUTOBOOT_MENUKEY)) if (IS_ENABLED(CONFIG_USE_AUTOBOOT_MENUKEY))
menukey = key; menukey = key;
break; break;

View File

@ -68,7 +68,7 @@ static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen)
#define CREAD_HIST_CHAR ('!') #define CREAD_HIST_CHAR ('!')
#define getcmd_putch(ch) putc(ch) #define getcmd_putch(ch) putc(ch)
#define getcmd_getch() getc() #define getcmd_getch() getchar()
#define getcmd_cbeep() getcmd_putch('\a') #define getcmd_cbeep() getcmd_putch('\a')
#define HIST_MAX 20 #define HIST_MAX 20
@ -571,7 +571,7 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer,
return -2; /* timed out */ return -2; /* timed out */
WATCHDOG_RESET(); /* Trigger watchdog, if needed */ WATCHDOG_RESET(); /* Trigger watchdog, if needed */
c = getc(); c = getchar();
/* /*
* Special character handling * Special character handling

View File

@ -131,7 +131,7 @@ static int console_setfile(int file, struct stdio_dev * dev)
*/ */
switch (file) { switch (file) {
case stdin: case stdin:
gd->jt->getc = getc; gd->jt->getc = getchar;
gd->jt->tstc = tstc; gd->jt->tstc = tstc;
break; break;
case stdout: case stdout:
@ -179,7 +179,7 @@ struct stdio_dev **console_devices[MAX_FILES];
int cd_count[MAX_FILES]; int cd_count[MAX_FILES];
/* /*
* This depends on tstc() always being called before getc(). * This depends on tstc() always being called before getchar().
* This is guaranteed to be true because this routine is called * This is guaranteed to be true because this routine is called
* only from fgetc() which assures it. * only from fgetc() which assures it.
* No attempt is made to demultiplex multiple input sources. * No attempt is made to demultiplex multiple input sources.
@ -404,7 +404,7 @@ int fprintf(int file, const char *fmt, ...)
/** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
int getc(void) int getchar(void)
{ {
#ifdef CONFIG_DISABLE_CONSOLE #ifdef CONFIG_DISABLE_CONSOLE
if (gd->flags & GD_FLG_DISABLE_CONSOLE) if (gd->flags & GD_FLG_DISABLE_CONSOLE)
@ -663,7 +663,7 @@ int ctrlc(void)
{ {
if (!ctrlc_disabled && gd->have_console) { if (!ctrlc_disabled && gd->have_console) {
if (tstc()) { if (tstc()) {
switch (getc()) { switch (getchar()) {
case 0x03: /* ^C - Control C */ case 0x03: /* ^C - Control C */
ctrlc_was_pressed = 1; ctrlc_was_pressed = 1;
return 1; return 1;
@ -685,10 +685,10 @@ int confirm_yesno(void)
/* Flush input */ /* Flush input */
while (tstc()) while (tstc())
getc(); getchar();
i = 0; i = 0;
while (i < sizeof(str_input)) { while (i < sizeof(str_input)) {
str_input[i] = getc(); str_input[i] = getchar();
putc(str_input[i]); putc(str_input[i]);
if (str_input[i] == '\r') if (str_input[i] == '\r')
break; break;

View File

@ -32,7 +32,7 @@ struct ymodem_fit_info {
static int getcymodem(void) { static int getcymodem(void) {
if (tstc()) if (tstc())
return (getc()); return (getchar());
return -1; return -1;
} }

View File

@ -72,7 +72,7 @@ CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c)
} }
if (tstc ()) if (tstc ())
{ {
*c = getc (); *c = getchar();
return 1; return 1;
} }
return 0; return 0;

View File

@ -705,7 +705,7 @@ phys_size_t __fsl_ddr_sdram(fsl_ddr_info_t *pinfo)
/* Compute it once normally. */ /* Compute it once normally. */
#ifdef CONFIG_FSL_DDR_INTERACTIVE #ifdef CONFIG_FSL_DDR_INTERACTIVE
if (tstc() && (getc() == 'd')) { /* we got a key press of 'd' */ if (tstc() && (getchar() == 'd')) { /* we got a key press of 'd' */
total_memory = fsl_ddr_interactive(pinfo, 0); total_memory = fsl_ddr_interactive(pinfo, 0);
} else if (fsl_ddr_interactive_env_var_exists()) { } else if (fsl_ddr_interactive_env_var_exists()) {
total_memory = fsl_ddr_interactive(pinfo, 1); total_memory = fsl_ddr_interactive(pinfo, 1);

View File

@ -394,7 +394,7 @@ bool stm32mp1_ddr_interactive(void *priv,
unsigned long start = get_timer(0); unsigned long start = get_timer(0);
while (1) { while (1) {
if (tstc() && (getc() == 'd')) { if (tstc() && (getchar() == 'd')) {
next_step = STEP_DDR_RESET; next_step = STEP_DDR_RESET;
break; break;
} }

View File

@ -413,7 +413,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op,
if ((flags & H_INTERACTIVE) != 0) if ((flags & H_INTERACTIVE) != 0)
while (1) { while (1) {
if (getc() == '\r') if (getchar() == '\r')
break; break;
} }

View File

@ -90,7 +90,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op,
if ((flags & H_INTERACTIVE) != 0) if ((flags & H_INTERACTIVE) != 0)
while (1) { while (1) {
if (getc() == '\r') if (getchar() == '\r')
break; break;
} }

View File

@ -8,7 +8,7 @@
#define EXPORT_FUNC(a, b, c, ...) #define EXPORT_FUNC(a, b, c, ...)
#endif #endif
EXPORT_FUNC(get_version, unsigned long, get_version, void) EXPORT_FUNC(get_version, unsigned long, get_version, void)
EXPORT_FUNC(getc, int, getc, void) EXPORT_FUNC(getchar, int, getc, void)
EXPORT_FUNC(tstc, int, tstc, void) EXPORT_FUNC(tstc, int, tstc, void)
EXPORT_FUNC(putc, void, putc, const char) EXPORT_FUNC(putc, void, putc, const char)
EXPORT_FUNC(puts, void, puts, const char *) EXPORT_FUNC(puts, void, puts, const char *)

View File

@ -5,7 +5,7 @@
#include <linux/compiler.h> #include <linux/compiler.h>
/* stdin */ /* stdin */
int getc(void); int getchar(void);
int tstc(void); int tstc(void);
/* stdout */ /* stdout */

View File

@ -104,7 +104,7 @@ static u8 read_console(void *data)
{ {
int ch; int ch;
ch = getc(); ch = getchar();
if (ch < 0) if (ch < 0)
ch = 0; ch = 0;
return ch; return ch;

View File

@ -76,7 +76,7 @@ static int term_get_char(s32 *c)
if (timer_get_us() > timeout) if (timer_get_us() > timeout)
return 1; return 1;
*c = getc(); *c = getchar();
return 0; return 0;
} }
@ -269,7 +269,7 @@ static int query_console_serial(int *rows, int *cols)
/* Empty input buffer */ /* Empty input buffer */
while (tstc()) while (tstc())
getc(); getchar();
/* /*
* Not all terminals understand CSI [18t for querying the console size. * Not all terminals understand CSI [18t for querying the console size.
@ -634,13 +634,13 @@ static int analyze_modifiers(struct efi_key_state *key_state)
{ {
int c, mod = 0, ret = 0; int c, mod = 0, ret = 0;
c = getc(); c = getchar();
if (c != ';') { if (c != ';') {
ret = c; ret = c;
if (c == '~') if (c == '~')
goto out; goto out;
c = getc(); c = getchar();
} }
for (;;) { for (;;) {
switch (c) { switch (c) {
@ -649,7 +649,7 @@ static int analyze_modifiers(struct efi_key_state *key_state)
mod += c - '0'; mod += c - '0';
/* fall through */ /* fall through */
case ';': case ';':
c = getc(); c = getchar();
break; break;
default: default:
goto out; goto out;
@ -692,25 +692,25 @@ static efi_status_t efi_cin_read_key(struct efi_key_data *key)
* Xterm Control Sequences * Xterm Control Sequences
* https://www.xfree86.org/4.8.0/ctlseqs.html * https://www.xfree86.org/4.8.0/ctlseqs.html
*/ */
ch = getc(); ch = getchar();
switch (ch) { switch (ch) {
case cESC: /* ESC */ case cESC: /* ESC */
pressed_key.scan_code = 23; pressed_key.scan_code = 23;
break; break;
case 'O': /* F1 - F4, End */ case 'O': /* F1 - F4, End */
ch = getc(); ch = getchar();
/* consider modifiers */ /* consider modifiers */
if (ch == 'F') { /* End */ if (ch == 'F') { /* End */
pressed_key.scan_code = 6; pressed_key.scan_code = 6;
break; break;
} else if (ch < 'P') { } else if (ch < 'P') {
set_shift_mask(ch - '0', &key->key_state); set_shift_mask(ch - '0', &key->key_state);
ch = getc(); ch = getchar();
} }
pressed_key.scan_code = ch - 'P' + 11; pressed_key.scan_code = ch - 'P' + 11;
break; break;
case '[': case '[':
ch = getc(); ch = getchar();
switch (ch) { switch (ch) {
case 'A'...'D': /* up, down right, left */ case 'A'...'D': /* up, down right, left */
pressed_key.scan_code = ch - 'A' + 1; pressed_key.scan_code = ch - 'A' + 1;
@ -868,7 +868,7 @@ static void efi_cin_check(void)
static void efi_cin_empty_buffer(void) static void efi_cin_empty_buffer(void)
{ {
while (tstc()) while (tstc())
getc(); getchar();
key_available = false; key_available = false;
} }

View File

@ -427,7 +427,7 @@ static int dm_test_usb_keyb(struct unit_test_state *uts)
for (c = pos->result; *c; ++c) { for (c = pos->result; *c; ++c) {
ut_asserteq(1, tstc()); ut_asserteq(1, tstc());
ut_asserteq(*c, getc()); ut_asserteq(*c, getchar());
} }
ut_asserteq(0, tstc()); ut_asserteq(0, tstc());
} }