introduce bb_putchar(). saves ~1800 on uclibc (less on glibc).
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c
index 5ad2349..435314e 100644
--- a/libbb/bb_askpass.c
+++ b/libbb/bb_askpass.c
@@ -69,7 +69,7 @@
}
tcsetattr(STDIN_FILENO, TCSANOW, &old);
- putchar('\n');
+ bb_putchar('\n');
fflush(stdout);
return ret;
}
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index a66398a..2db85d0 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -111,15 +111,15 @@
#endif
{
if (initial_settings.c_lflag & ECHO)
- putchar(c);
+ bb_putchar(c);
}
if (++cmdedit_x >= cmdedit_termw) {
/* terminal is scrolled down */
cmdedit_y++;
cmdedit_x = 0;
/* destroy "(auto)margin" */
- putchar(next_char);
- putchar('\b');
+ bb_putchar(next_char);
+ bb_putchar('\b');
}
// Huh? What if command_ps[cursor] == '\0' (we are at the end already?)
cursor++;
@@ -137,7 +137,7 @@
{
input_end();
if (cmdedit_x)
- putchar('\n');
+ bb_putchar('\n');
}
@@ -149,7 +149,7 @@
static void beep(void)
{
- putchar('\007');
+ bb_putchar('\007');
}
/* Move back one character */
@@ -197,7 +197,7 @@
{
if (y > 0) /* up to start y */
printf("\033[%dA", y);
- putchar('\r');
+ bb_putchar('\r');
put_prompt();
input_end(); /* rewrite */
printf("\033[J"); /* erase after cursor */
@@ -1585,8 +1585,8 @@
beep();
else {
*(command + cursor) = c;
- putchar(c);
- putchar('\b');
+ bb_putchar(c);
+ bb_putchar('\b');
}
break;
#endif /* FEATURE_COMMAND_EDITING_VI */
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 2215bb8..eb1633b 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -456,6 +456,14 @@
return pos + 1;
}
+int bb_putchar(int ch)
+{
+ /* time.c needs putc(ch, stdout), not putchar(ch).
+ * it does "stdout = stderr;", but then glibc's putchar()
+ * doesn't work as expected. bad glibc, bad */
+ return putc(ch, stdout);
+}
+
// Die with an error message if we can't malloc() enough space and do an
// sprintf() into that space.
char *xasprintf(const char *format, ...)