Skip to contentSkip to conversation

common: rename getc() to getchar()

PATCH New Heinrich Schuchardt 3 participants 4 messages Oct 7, 2020 – Oct 23, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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().

---
 api/api.c                                   |  2 +-
 cmd/bootmenu.c                              |  4 +-
 cmd/load.c                                  | 44 ++++++++++-----------
 common/autoboot.c                           | 10 ++---
 common/cli_readline.c                       |  4 +-
 common/console.c                            | 12 +++---
 common/spl/spl_ymodem.c                     |  2 +-
 common/xyzModem.c                           |  2 +-
 drivers/ddr/fsl/main.c                      |  2 +-
 drivers/ram/stm32mp1/stm32mp1_interactive.c |  2 +-
 drivers/serial/serial-uclass.c              |  2 +-
 drivers/serial/serial.c                     |  2 +-
 include/_exports.h                          |  2 +-
 include/stdio.h                             |  2 +-
 lib/charset.c                               |  2 +-
 lib/efi_loader/efi_console.c                | 20 +++++-----
 test/dm/usb.c                               |  2 +-
 17 files changed, 58 insertions(+), 58 deletions(-)
api/api.c +1 -1
index c7f5db776a..493b77f809 100644
@@ -57,7 +57,7 @@ static int API_getc(va_list ap)
 	if ((c = (int *)va_arg(ap, uintptr_t)) == NULL)
 		return API_EINVAL;
 
-	*c = getc();
+	*c = getchar();
 	return 0;
 }
 
cmd/bootmenu.c +2 -2
index 18efe25751..1ba7b622e5 100644
@@ -99,7 +99,7 @@ static void bootmenu_autoboot_loop(struct bootmenu_data *menu,
 			}
 
 			menu->delay = -1;
-			c = getc();
+			c = getchar();
 
 			switch (c) {
 			case '\e':
@@ -141,7 +141,7 @@ static void bootmenu_loop(struct bootmenu_data *menu,
 		mdelay(10);
 	}
 
-	c = getc();
+	c = getchar();
 
 	switch (*esc) {
 	case 0:
cmd/load.c +22 -22

172 lines not on this page · raw message

common/autoboot.c +5 -5
index 6d78716a26..28a398a08a 100644
@@ -117,7 +117,7 @@ static int passwd_abort_sha256(uint64_t etime)
 				return 0;
 			}
 
-			presskey[presskey_len++] = getc();
+			presskey[presskey_len++] = getchar();
 
 			/* Calculate sha256 upon each new char */
 			hash_block(algo_name, (const void *)presskey,
@@ -189,12 +189,12 @@ static int passwd_abort_key(uint64_t etime)
 	do {
 		if (tstc()) {
 			if (presskey_len < presskey_max) {
-				presskey[presskey_len++] = getc();
+				presskey[presskey_len++] = getchar();
 			} else {
 				for (i = 0; i < presskey_max - 1; i++)
 					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
 	 */
 	if (tstc()) {	/* we got a key press	*/
-		(void) getc();  /* consume input	*/
+		getchar();	/* consume input	*/
 		puts("\b\b\b 0");
 		abort = 1;	/* don't auto boot	*/
 	}
@@ -272,7 +272,7 @@ static int abortboot_single_key(int bootdelay)
 
 				abort  = 1;	/* don't auto boot	*/
 				bootdelay = 0;	/* no more delay	*/
-				key = getc(); /* consume input	*/
+				key = getchar();/* consume input	*/
 				if (IS_ENABLED(CONFIG_USE_AUTOBOOT_MENUKEY))
 					menukey = key;
 				break;
common/cli_readline.c +2 -2
index 1f1e28c6d8..47b876285c 100644
@@ -68,7 +68,7 @@ static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen)
 #define CREAD_HIST_CHAR		('!')
 
 #define getcmd_putch(ch)	putc(ch)
-#define getcmd_getch()		getc()
+#define getcmd_getch()		getchar()
 #define getcmd_cbeep()		getcmd_putch('\a')
 
 #define HIST_MAX		20
@@ -571,7 +571,7 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer,
 			return -2;	/* timed out */
 		WATCHDOG_RESET();	/* Trigger watchdog, if needed */
 
-		c = getc();
+		c = getchar();
 
 		/*
 		 * Special character handling
common/console.c +6 -6
index 8e50af1f9d..3348436da6 100644
@@ -131,7 +131,7 @@ static int console_setfile(int file, struct stdio_dev * dev)
 		 */
 		switch (file) {
 		case stdin:
-			gd->jt->getc = getc;
+			gd->jt->getc = getchar;
 			gd->jt->tstc = tstc;
 			break;
 		case stdout:
@@ -179,7 +179,7 @@ struct stdio_dev **console_devices[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
  * only from fgetc() which assures it.
  * 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 *****************************/
 
-int getc(void)
+int getchar(void)
 {
 #ifdef CONFIG_DISABLE_CONSOLE
 	if (gd->flags & GD_FLG_DISABLE_CONSOLE)
@@ -663,7 +663,7 @@ int ctrlc(void)
 {
 	if (!ctrlc_disabled && gd->have_console) {
 		if (tstc()) {
-			switch (getc()) {
+			switch (getchar()) {
 			case 0x03:		/* ^C - Control C */
 				ctrlc_was_pressed = 1;
 				return 1;
@@ -685,10 +685,10 @@ int confirm_yesno(void)
 
 	/* Flush input */
 	while (tstc())
-		getc();
+		getchar();
 	i = 0;
 	while (i < sizeof(str_input)) {
-		str_input[i] = getc();
+		str_input[i] = getchar();
 		putc(str_input[i]);
 		if (str_input[i] == '\r')
 			break;
common/spl/spl_ymodem.c +1 -1
index 284512478f..e979f780ad 100644
@@ -32,7 +32,7 @@ struct ymodem_fit_info {
 
 static int getcymodem(void) {
 	if (tstc())
-		return (getc());
+		return (getchar());
 	return -1;
 }
 
common/xyzModem.c +1 -1
index 6bf2375671..fc3459ebba 100644
@@ -72,7 +72,7 @@ CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c)
     }
   if (tstc ())
     {
-      *c = getc ();
+      *c = getchar();
       return 1;
     }
   return 0;
drivers/ddr/fsl/main.c +1 -1
index 84139b85c3..c02badd4a8 100644
@@ -705,7 +705,7 @@ phys_size_t __fsl_ddr_sdram(fsl_ddr_info_t *pinfo)
 
 	/* Compute it once normally. */
 #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);
 	} else if (fsl_ddr_interactive_env_var_exists()) {
 		total_memory = fsl_ddr_interactive(pinfo, 1);
drivers/ram/stm32mp1/stm32mp1_interactive.c +1 -1
index 38390c0d55..5a5d067046 100644
@@ -394,7 +394,7 @@ bool stm32mp1_ddr_interactive(void *priv,
 		unsigned long start = get_timer(0);
 
 		while (1) {
-			if (tstc() && (getc() == 'd')) {
+			if (tstc() && (getchar() == 'd')) {
 				next_step = STEP_DDR_RESET;
 				break;
 			}
drivers/serial/serial-uclass.c +1 -1
index 0027625ebf..f3c25d4216 100644
@@ -413,7 +413,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op,
 
 		if ((flags & H_INTERACTIVE) != 0)
 			while (1) {
-				if (getc() == '\r')
+				if (getchar() == '\r')
 					break;
 			}
 
drivers/serial/serial.c +1 -1
index 53358acb81..355659ba05 100644
@@ -90,7 +90,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op,
 
 		if ((flags & H_INTERACTIVE) != 0)
 			while (1) {
-				if (getc() == '\r')
+				if (getchar() == '\r')
 					break;
 			}
 
include/_exports.h +1 -1
index 1e9ba86108..aeb666c847 100644
@@ -8,7 +8,7 @@
 #define EXPORT_FUNC(a, b, c, ...)
 #endif
 	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(putc, void, putc, const char)
 	EXPORT_FUNC(puts, void, puts, const char *)
include/stdio.h +1 -1
index aedf374452..039f7df689 100644
@@ -5,7 +5,7 @@
 #include <linux/compiler.h>
 
 /* stdin */
-int getc(void);
+int getchar(void);
 int tstc(void);
 
 /* stdout */
lib/charset.c +1 -1
index a28034ee1f..5686d6fb59 100644
@@ -104,7 +104,7 @@ static u8 read_console(void *data)
 {
 	int ch;
 
-	ch = getc();
+	ch = getchar();
 	if (ch < 0)
 		ch = 0;
 	return ch;
lib/efi_loader/efi_console.c +10 -10
index 426de77951..011accab78 100644
@@ -76,7 +76,7 @@ static int term_get_char(s32 *c)
 		if (timer_get_us() > timeout)
 			return 1;
 
-	*c = getc();
+	*c = getchar();
 	return 0;
 }
 
@@ -269,7 +269,7 @@ static int query_console_serial(int *rows, int *cols)
 
 	/* Empty input buffer */
 	while (tstc())
-		getc();
+		getchar();
 
 	/*
 	 * 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;
 
-	c = getc();
+	c = getchar();
 
 	if (c != ';') {
 		ret = c;
 		if (c == '~')
 			goto out;
-		c = getc();
+		c = getchar();
 	}
 	for (;;) {
 		switch (c) {
@@ -649,7 +649,7 @@ static int analyze_modifiers(struct efi_key_state *key_state)
 			mod += c - '0';
 		/* fall through */
 		case ';':
-			c = getc();
+			c = getchar();
 			break;
 		default:
 			goto out;
@@ -692,25 +692,25 @@ static efi_status_t efi_cin_read_key(struct efi_key_data *key)
 		 * Xterm Control Sequences
 		 * https://www.xfree86.org/4.8.0/ctlseqs.html
 		 */
-		ch = getc();
+		ch = getchar();
 		switch (ch) {
 		case cESC: /* ESC */
 			pressed_key.scan_code = 23;
 			break;
 		case 'O': /* F1 - F4, End */
-			ch = getc();
+			ch = getchar();
 			/* consider modifiers */
 			if (ch == 'F') { /* End */
 				pressed_key.scan_code = 6;
 				break;
 			} else if (ch < 'P') {
 				set_shift_mask(ch - '0', &key->key_state);
-				ch = getc();
+				ch = getchar();
 			}
 			pressed_key.scan_code = ch - 'P' + 11;
 			break;
 		case '[':
-			ch = getc();
+			ch = getchar();
 			switch (ch) {
 			case 'A'...'D': /* up, down right, left */
 				pressed_key.scan_code = ch - 'A' + 1;
@@ -868,7 +868,7 @@ static void efi_cin_check(void)
 static void efi_cin_empty_buffer(void)
 {
 	while (tstc())
-		getc();
+		getchar();
 	key_available = false;
 }
 
test/dm/usb.c +1 -1
index db4b8ba0f7..5d6ceefce0 100644
@@ -427,7 +427,7 @@ static int dm_test_usb_keyb(struct unit_test_state *uts)
 
 		for (c = pos->result; *c; ++c) {
 			ut_asserteq(1, tstc());
-			ut_asserteq(*c, getc());
+			ut_asserteq(*c, getchar());
 		}
 		ut_asserteq(0, tstc());
 	}

--
2.28.0

#1 lore raw

PATCH 1/1 common: rename getc() to getchar()

Quoted 7 lines · Heinrich Schuchardt

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.

Quoted 7 lines

int getc(void)

The sandbox crashes when called with parameter -l.

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

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201007/33a7d173/attachment.sig>
#2 lore raw

PATCH 1/1 common: rename getc() to getchar()

In reply to Heinrich Schuchardt

Hi Heinrich,

Quoted 11 lines · Heinrich Schuchardt

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.

Just a nit here. I don't think the issue is that getc() has different parameters. I believe it is the fact that we are overriding the getc() in the C library. It wouldn't help if we changed the parameters, for example, as it is still wrong for it to call the U-Boot version.

Quoted 15 lines

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

---
 api/api.c                                   |  2 +-
 cmd/bootmenu.c                              |  4 +-
 cmd/load.c                                  | 44 ++++++++++-----------
 common/autoboot.c                           | 10 ++---
 common/cli_readline.c                       |  4 +-
 common/console.c                            | 12 +++---
 common/spl/spl_ymodem.c                     |  2 +-
 common/xyzModem.c                           |  2 +-
 drivers/ddr/fsl/main.c                      |  2 +-
 drivers/ram/stm32mp1/stm32mp1_interactive.c |  2 +-
Quoted 8 lines
 drivers/serial/serial-uclass.c              |  2 +-
 drivers/serial/serial.c                     |  2 +-
 include/_exports.h                          |  2 +-
 include/stdio.h                             |  2 +-
 lib/charset.c                               |  2 +-
 lib/efi_loader/efi_console.c                | 20 +++++-----
 test/dm/usb.c                               |  2 +-
 17 files changed, 58 insertions(+), 58 deletions(-)

Regards,
Simon

#3 lore raw

PATCH 1/1 common: rename getc() to getchar()

In reply to Heinrich Schuchardt
Quoted 9 lines · Heinrich Schuchardt

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)

Quoted 7 lines

The sandbox crashes when called with parameter -l.

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

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201022/99e44332/attachment.sig>