console: Report an error when output buffer is exhausted

If the console output buffer is exhausted, characters are silently dropped
from the end. Detect this condition and report an error when reading back
the characters.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/common/console.c b/common/console.c
index 561cdf3..73edb28 100644
--- a/common/console.c
+++ b/common/console.c
@@ -95,16 +95,22 @@
 {
 	if (!(gd->flags & GD_FLG_RECORD))
 		return;
-	if  (gd->console_out.start)
-		membuff_putbyte((struct membuff *)&gd->console_out, c);
+	if  (gd->console_out.start &&
+	     !membuff_putbyte((struct membuff *)&gd->console_out, c))
+		gd->flags |= GD_FLG_RECORD_OVF;
 }
 
 static void console_record_puts(const char *s)
 {
 	if (!(gd->flags & GD_FLG_RECORD))
 		return;
-	if  (gd->console_out.start)
-		membuff_put((struct membuff *)&gd->console_out, s, strlen(s));
+	if  (gd->console_out.start) {
+		int len = strlen(s);
+
+		if (membuff_put((struct membuff *)&gd->console_out, s, len) !=
+		    len)
+			gd->flags |= GD_FLG_RECORD_OVF;
+	}
 }
 
 static int console_record_getc(void)
@@ -742,6 +748,7 @@
 {
 	membuff_purge((struct membuff *)&gd->console_out);
 	membuff_purge((struct membuff *)&gd->console_in);
+	gd->flags &= ~GD_FLG_RECORD_OVF;
 }
 
 int console_record_reset_enable(void)
@@ -754,6 +761,9 @@
 
 int console_record_readline(char *str, int maxlen)
 {
+	if (gd->flags & GD_FLG_RECORD_OVF)
+		return -ENOSPC;
+
 	return membuff_readline((struct membuff *)&gd->console_out, str,
 				maxlen, ' ');
 }