From 79ec7d375a4cc969a7e2ee36edca52074fa71219 Mon Sep 17 00:00:00 2001
From: Rahix <rahix@rahix.de>
Date: Mon, 29 Jul 2019 18:05:11 +0200
Subject: [PATCH] fix(pycardium): Fix stubbed snprintf messing up readline

Signed-off-by: Rahix <rahix@rahix.de>
---
 pycardium/patch.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/pycardium/patch.c b/pycardium/patch.c
index 902653ec..bf85e5bd 100644
--- a/pycardium/patch.c
+++ b/pycardium/patch.c
@@ -49,8 +49,22 @@ int puts(const char *s)
 /* Used by mp_hal_move_cursor_back() */
 int snprintf(char *str, size_t size, const char *format, ...)
 {
-	/* TODO: What should we do with this? */
-	return -EIO;
+	/*
+	 * There is one known place where snprintf is used:  The
+	 * mp_hal_move_cursor_back() function from mp-readline.
+	 * This stub implementation just implements printf for
+	 * that one case.
+	 */
+	if (format[0] != '\x1B' || size != 6) {
+		return -EIO;
+	}
+
+	va_list ap;
+	va_start(ap, format);
+	printf("\x1B[%uD", va_arg(ap, unsigned int));
+	va_end(ap);
+
+	return -1;
 }
 
 /* Use by assert() */
-- 
GitLab