From d7b9053e23fd5dc082ea82d748a23916c78d0a60 Mon Sep 17 00:00:00 2001
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Fri, 4 Sep 2015 19:32:54 +0200
Subject: [PATCH] sys: shell: work around inlined putchar

---
 sys/shell/shell.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/sys/shell/shell.c b/sys/shell/shell.c
index 3b48778984..fba645dea8 100644
--- a/sys/shell/shell.c
+++ b/sys/shell/shell.c
@@ -32,6 +32,16 @@
 #include "shell.h"
 #include "shell_commands.h"
 
+#ifdef MODULE_NEWLIB
+/* use local copy of putchar, as it seems to be inlined,
+ * enlarging code by 50% */
+static void _putchar(int c) {
+    putchar(c);
+}
+#else
+#define _putchar putchar
+#endif
+
 static shell_command_handler_t find_handler(const shell_command_t *command_list, char *command)
 {
     const shell_command_t *command_lists[] = {
@@ -224,8 +234,8 @@ static int readline(char *buf, size_t size)
         /* DOS newlines are handled like hitting enter twice, but empty lines are ignored. */
         if (c == '\r' || c == '\n') {
             *line_buf_ptr = '\0';
-            putchar('\r');
-            putchar('\n');
+            _putchar('\r');
+            _putchar('\n');
 
             /* return 1 if line is empty, 0 otherwise */
             return line_buf_ptr == buf;
@@ -239,21 +249,21 @@ static int readline(char *buf, size_t size)
 
             *--line_buf_ptr = '\0';
             /* white-tape the character */
-            putchar('\b');
-            putchar(' ');
-            putchar('\b');
+            _putchar('\b');
+            _putchar(' ');
+            _putchar('\b');
         }
         else {
             *line_buf_ptr++ = c;
-            putchar(c);
+            _putchar(c);
         }
     }
 }
 
 static inline void print_prompt(void)
 {
-    putchar('>');
-    putchar(' ');
+    _putchar('>');
+    _putchar(' ');
 
 #ifdef MODULE_NEWLIB
     fflush(stdout);
-- 
GitLab