*: introduce and use ffulsh_all()
function old new delta buffer_fill_and_print 179 196 +17 fflush_all - 9 +9 spawn 87 92 +5 rtcwake_main 455 453 -2 ... alarm_intr 93 84 -9 readcmd 1072 1062 -10 bb_ask 345 333 -12 more_main 845 832 -13 flush_stdout_stderr 42 23 -19 xfflush_stdout 27 - -27 flush_stderr 30 - -30 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 2/50 up/down: 31/-397) Total: -366 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -55,7 +55,7 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
|
||||
}
|
||||
|
||||
fputs(prompt, stdout);
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
ret = NULL;
|
||||
/* On timeout or Ctrl-C, read will hopefully be interrupted,
|
||||
* and we return NULL */
|
||||
@@ -77,6 +77,6 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
|
||||
|
||||
tcsetattr_stdin_TCSANOW(&oldtio);
|
||||
bb_putchar('\n');
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ void FAST_FUNC bb_info_msg(const char *s, ...)
|
||||
if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG))
|
||||
syslog(LOG_INFO, "%s", msg);
|
||||
if (logmode & LOGMODE_STDIO) {
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
/* used = strlen(msg); - must be true already */
|
||||
msg[used++] = '\n';
|
||||
full_write(STDOUT_FILENO, msg, used);
|
||||
|
||||
@@ -373,7 +373,7 @@ static void input_backward(unsigned num)
|
||||
static void put_prompt(void)
|
||||
{
|
||||
out1str(cmdedit_prompt);
|
||||
fflush(NULL);
|
||||
fflush_all();
|
||||
#if ENABLE_FEATURE_EDITING_ASK_TERMINAL
|
||||
{
|
||||
/* Ask terminal where is the cursor now.
|
||||
@@ -411,7 +411,7 @@ static void put_prompt(void)
|
||||
if (safe_poll(&pfd, 1, 0) == 0) {
|
||||
S.sent_ESC_br6n = 1;
|
||||
out1str("\033" "[6n");
|
||||
fflush(NULL); /* make terminal see it ASAP! */
|
||||
fflush_all(); /* make terminal see it ASAP! */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1636,7 +1636,7 @@ static void cmdedit_setwidth(unsigned w, int redraw_flg)
|
||||
int new_y = (cursor + cmdedit_prmt_len) / w;
|
||||
/* redraw */
|
||||
redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor);
|
||||
fflush(NULL);
|
||||
fflush_all();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1748,7 +1748,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
||||
) {
|
||||
/* Happens when e.g. stty -echo was run before */
|
||||
parse_and_put_prompt(prompt);
|
||||
/* fflush(stdout); - done by parse_and_put_prompt */
|
||||
/* fflush_all(); - done by parse_and_put_prompt */
|
||||
if (fgets(command, maxsize, stdin) == NULL)
|
||||
len = -1; /* EOF or error */
|
||||
else
|
||||
@@ -1841,7 +1841,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
||||
};
|
||||
int32_t ic, ic_raw;
|
||||
|
||||
fflush(NULL);
|
||||
fflush_all();
|
||||
ic = ic_raw = lineedit_read_key(read_key_buffer);
|
||||
|
||||
#if ENABLE_FEATURE_EDITING_VI
|
||||
@@ -2245,7 +2245,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
||||
tcsetattr_stdin_TCSANOW(&initial_settings);
|
||||
/* restore SIGWINCH handler */
|
||||
signal(SIGWINCH, previous_SIGWINCH_handler);
|
||||
fflush(NULL);
|
||||
fflush_all();
|
||||
|
||||
len = command_len;
|
||||
DEINIT_S();
|
||||
@@ -2259,7 +2259,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
||||
int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize)
|
||||
{
|
||||
fputs(prompt, stdout);
|
||||
fflush(NULL);
|
||||
fflush_all();
|
||||
fgets(command, maxsize, stdin);
|
||||
return strlen(command);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
|
||||
fputs(outbuf, stdout);
|
||||
}
|
||||
fclose(fp);
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
}
|
||||
|
||||
void FAST_FUNC print_login_prompt(void)
|
||||
@@ -94,7 +94,7 @@ void FAST_FUNC print_login_prompt(void)
|
||||
|
||||
fputs(hostname, stdout);
|
||||
fputs(LOGIN, stdout);
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
free(hostname);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
|
||||
}
|
||||
|
||||
if (logmode & LOGMODE_STDIO) {
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
full_write(STDERR_FILENO, msg, used);
|
||||
}
|
||||
if (logmode & LOGMODE_SYSLOG) {
|
||||
@@ -125,8 +125,8 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
|
||||
iov[1].iov_len = 2;
|
||||
/*iov[2].iov_base = msgc;*/
|
||||
/*iov[2].iov_len = used;*/
|
||||
fflush(stdout);
|
||||
writev(2, iov, 3);
|
||||
fflush_all();
|
||||
writev(STDERR_FILENO, iov, 3);
|
||||
}
|
||||
if (logmode & LOGMODE_SYSLOG) {
|
||||
syslog(LOG_ERR, "%s", msgc);
|
||||
|
||||
@@ -25,7 +25,7 @@ pid_t FAST_FUNC spawn(char **argv)
|
||||
volatile int failed;
|
||||
pid_t pid;
|
||||
|
||||
// Ain't it a good place to fflush(NULL)?
|
||||
fflush_all();
|
||||
|
||||
/* Be nice to nommu machines. */
|
||||
failed = 0;
|
||||
|
||||
@@ -255,12 +255,9 @@ void FAST_FUNC die_if_ferror_stdout(void)
|
||||
die_if_ferror(stdout, bb_msg_standard_output);
|
||||
}
|
||||
|
||||
// Die with an error message if we have trouble flushing stdout.
|
||||
void FAST_FUNC xfflush_stdout(void)
|
||||
int FAST_FUNC fflush_all(void)
|
||||
{
|
||||
if (fflush(stdout)) {
|
||||
bb_perror_msg_and_die(bb_msg_standard_output);
|
||||
}
|
||||
return fflush(NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -276,9 +273,9 @@ int FAST_FUNC bb_putchar(int ch)
|
||||
* then close that file. */
|
||||
void FAST_FUNC xprint_and_close_file(FILE *file)
|
||||
{
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
// copyfd outputs error messages for us.
|
||||
if (bb_copyfd_eof(fileno(file), 1) == -1)
|
||||
if (bb_copyfd_eof(fileno(file), STDOUT_FILENO) == -1)
|
||||
xfunc_die();
|
||||
|
||||
fclose(file);
|
||||
|
||||
Reference in New Issue
Block a user