aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-02 14:19:51 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-02 14:19:51 +0100
commit8131eea3dce5fba0dfb78e6083d1730423fad20b (patch)
treec098d7ba6ef9f4745425a29a330480e6088d6d9a /libbb
parent0d8ea64af618dc83c3291b3b598636ed3d0854e4 (diff)
downloadbusybox-8131eea3dce5fba0dfb78e6083d1730423fad20b.tar.gz
*: 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>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/bb_askpass.c4
-rw-r--r--libbb/info_msg.c2
-rw-r--r--libbb/lineedit.c14
-rw-r--r--libbb/login.c4
-rw-r--r--libbb/verror_msg.c6
-rw-r--r--libbb/vfork_daemon_rexec.c2
-rw-r--r--libbb/xfuncs_printf.c11
7 files changed, 20 insertions, 23 deletions
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c
index 073175c1f..f9b918cec 100644
--- a/libbb/bb_askpass.c
+++ b/libbb/bb_askpass.c
@@ -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;
}
diff --git a/libbb/info_msg.c b/libbb/info_msg.c
index 8b8a1fcca..5f375d43b 100644
--- a/libbb/info_msg.c
+++ b/libbb/info_msg.c
@@ -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);
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 0f7ab8c94..a9972576e 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -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);
}
diff --git a/libbb/login.c b/libbb/login.c
index 07247a8c5..740c588f3 100644
--- a/libbb/login.c
+++ b/libbb/login.c
@@ -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);
}
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
index 506b9066a..70f792f39 100644
--- a/libbb/verror_msg.c
+++ b/libbb/verror_msg.c
@@ -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);
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 27efb0e37..9be901722 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -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;
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 241887ace..644134a0e 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -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);