diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-02 14:19:51 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-02 14:19:51 +0100 |
commit | 8131eea3dce5fba0dfb78e6083d1730423fad20b (patch) | |
tree | c098d7ba6ef9f4745425a29a330480e6088d6d9a /libbb | |
parent | 0d8ea64af618dc83c3291b3b598636ed3d0854e4 (diff) | |
download | busybox-w32-8131eea3dce5fba0dfb78e6083d1730423fad20b.tar.gz busybox-w32-8131eea3dce5fba0dfb78e6083d1730423fad20b.tar.bz2 busybox-w32-8131eea3dce5fba0dfb78e6083d1730423fad20b.zip |
*: 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.c | 4 | ||||
-rw-r--r-- | libbb/info_msg.c | 2 | ||||
-rw-r--r-- | libbb/lineedit.c | 14 | ||||
-rw-r--r-- | libbb/login.c | 4 | ||||
-rw-r--r-- | libbb/verror_msg.c | 6 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 2 | ||||
-rw-r--r-- | libbb/xfuncs_printf.c | 11 |
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) | |||
55 | } | 55 | } |
56 | 56 | ||
57 | fputs(prompt, stdout); | 57 | fputs(prompt, stdout); |
58 | fflush(stdout); | 58 | fflush_all(); |
59 | ret = NULL; | 59 | ret = NULL; |
60 | /* On timeout or Ctrl-C, read will hopefully be interrupted, | 60 | /* On timeout or Ctrl-C, read will hopefully be interrupted, |
61 | * and we return NULL */ | 61 | * and we return NULL */ |
@@ -77,6 +77,6 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | |||
77 | 77 | ||
78 | tcsetattr_stdin_TCSANOW(&oldtio); | 78 | tcsetattr_stdin_TCSANOW(&oldtio); |
79 | bb_putchar('\n'); | 79 | bb_putchar('\n'); |
80 | fflush(stdout); | 80 | fflush_all(); |
81 | return ret; | 81 | return ret; |
82 | } | 82 | } |
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, ...) | |||
44 | if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) | 44 | if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) |
45 | syslog(LOG_INFO, "%s", msg); | 45 | syslog(LOG_INFO, "%s", msg); |
46 | if (logmode & LOGMODE_STDIO) { | 46 | if (logmode & LOGMODE_STDIO) { |
47 | fflush(stdout); | 47 | fflush_all(); |
48 | /* used = strlen(msg); - must be true already */ | 48 | /* used = strlen(msg); - must be true already */ |
49 | msg[used++] = '\n'; | 49 | msg[used++] = '\n'; |
50 | full_write(STDOUT_FILENO, msg, used); | 50 | 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) | |||
373 | static void put_prompt(void) | 373 | static void put_prompt(void) |
374 | { | 374 | { |
375 | out1str(cmdedit_prompt); | 375 | out1str(cmdedit_prompt); |
376 | fflush(NULL); | 376 | fflush_all(); |
377 | #if ENABLE_FEATURE_EDITING_ASK_TERMINAL | 377 | #if ENABLE_FEATURE_EDITING_ASK_TERMINAL |
378 | { | 378 | { |
379 | /* Ask terminal where is the cursor now. | 379 | /* Ask terminal where is the cursor now. |
@@ -411,7 +411,7 @@ static void put_prompt(void) | |||
411 | if (safe_poll(&pfd, 1, 0) == 0) { | 411 | if (safe_poll(&pfd, 1, 0) == 0) { |
412 | S.sent_ESC_br6n = 1; | 412 | S.sent_ESC_br6n = 1; |
413 | out1str("\033" "[6n"); | 413 | out1str("\033" "[6n"); |
414 | fflush(NULL); /* make terminal see it ASAP! */ | 414 | fflush_all(); /* make terminal see it ASAP! */ |
415 | } | 415 | } |
416 | } | 416 | } |
417 | #endif | 417 | #endif |
@@ -1636,7 +1636,7 @@ static void cmdedit_setwidth(unsigned w, int redraw_flg) | |||
1636 | int new_y = (cursor + cmdedit_prmt_len) / w; | 1636 | int new_y = (cursor + cmdedit_prmt_len) / w; |
1637 | /* redraw */ | 1637 | /* redraw */ |
1638 | redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor); | 1638 | redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor); |
1639 | fflush(NULL); | 1639 | fflush_all(); |
1640 | } | 1640 | } |
1641 | } | 1641 | } |
1642 | 1642 | ||
@@ -1748,7 +1748,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li | |||
1748 | ) { | 1748 | ) { |
1749 | /* Happens when e.g. stty -echo was run before */ | 1749 | /* Happens when e.g. stty -echo was run before */ |
1750 | parse_and_put_prompt(prompt); | 1750 | parse_and_put_prompt(prompt); |
1751 | /* fflush(stdout); - done by parse_and_put_prompt */ | 1751 | /* fflush_all(); - done by parse_and_put_prompt */ |
1752 | if (fgets(command, maxsize, stdin) == NULL) | 1752 | if (fgets(command, maxsize, stdin) == NULL) |
1753 | len = -1; /* EOF or error */ | 1753 | len = -1; /* EOF or error */ |
1754 | else | 1754 | else |
@@ -1841,7 +1841,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li | |||
1841 | }; | 1841 | }; |
1842 | int32_t ic, ic_raw; | 1842 | int32_t ic, ic_raw; |
1843 | 1843 | ||
1844 | fflush(NULL); | 1844 | fflush_all(); |
1845 | ic = ic_raw = lineedit_read_key(read_key_buffer); | 1845 | ic = ic_raw = lineedit_read_key(read_key_buffer); |
1846 | 1846 | ||
1847 | #if ENABLE_FEATURE_EDITING_VI | 1847 | #if ENABLE_FEATURE_EDITING_VI |
@@ -2245,7 +2245,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li | |||
2245 | tcsetattr_stdin_TCSANOW(&initial_settings); | 2245 | tcsetattr_stdin_TCSANOW(&initial_settings); |
2246 | /* restore SIGWINCH handler */ | 2246 | /* restore SIGWINCH handler */ |
2247 | signal(SIGWINCH, previous_SIGWINCH_handler); | 2247 | signal(SIGWINCH, previous_SIGWINCH_handler); |
2248 | fflush(NULL); | 2248 | fflush_all(); |
2249 | 2249 | ||
2250 | len = command_len; | 2250 | len = command_len; |
2251 | DEINIT_S(); | 2251 | DEINIT_S(); |
@@ -2259,7 +2259,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li | |||
2259 | int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize) | 2259 | int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize) |
2260 | { | 2260 | { |
2261 | fputs(prompt, stdout); | 2261 | fputs(prompt, stdout); |
2262 | fflush(NULL); | 2262 | fflush_all(); |
2263 | fgets(command, maxsize, stdin); | 2263 | fgets(command, maxsize, stdin); |
2264 | return strlen(command); | 2264 | return strlen(command); |
2265 | } | 2265 | } |
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) | |||
85 | fputs(outbuf, stdout); | 85 | fputs(outbuf, stdout); |
86 | } | 86 | } |
87 | fclose(fp); | 87 | fclose(fp); |
88 | fflush(stdout); | 88 | fflush_all(); |
89 | } | 89 | } |
90 | 90 | ||
91 | void FAST_FUNC print_login_prompt(void) | 91 | void FAST_FUNC print_login_prompt(void) |
@@ -94,7 +94,7 @@ void FAST_FUNC print_login_prompt(void) | |||
94 | 94 | ||
95 | fputs(hostname, stdout); | 95 | fputs(hostname, stdout); |
96 | fputs(LOGIN, stdout); | 96 | fputs(LOGIN, stdout); |
97 | fflush(stdout); | 97 | fflush_all(); |
98 | free(hostname); | 98 | free(hostname); |
99 | } | 99 | } |
100 | 100 | ||
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) | |||
64 | } | 64 | } |
65 | 65 | ||
66 | if (logmode & LOGMODE_STDIO) { | 66 | if (logmode & LOGMODE_STDIO) { |
67 | fflush(stdout); | 67 | fflush_all(); |
68 | full_write(STDERR_FILENO, msg, used); | 68 | full_write(STDERR_FILENO, msg, used); |
69 | } | 69 | } |
70 | if (logmode & LOGMODE_SYSLOG) { | 70 | if (logmode & LOGMODE_SYSLOG) { |
@@ -125,8 +125,8 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr) | |||
125 | iov[1].iov_len = 2; | 125 | iov[1].iov_len = 2; |
126 | /*iov[2].iov_base = msgc;*/ | 126 | /*iov[2].iov_base = msgc;*/ |
127 | /*iov[2].iov_len = used;*/ | 127 | /*iov[2].iov_len = used;*/ |
128 | fflush(stdout); | 128 | fflush_all(); |
129 | writev(2, iov, 3); | 129 | writev(STDERR_FILENO, iov, 3); |
130 | } | 130 | } |
131 | if (logmode & LOGMODE_SYSLOG) { | 131 | if (logmode & LOGMODE_SYSLOG) { |
132 | syslog(LOG_ERR, "%s", msgc); | 132 | 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) | |||
25 | volatile int failed; | 25 | volatile int failed; |
26 | pid_t pid; | 26 | pid_t pid; |
27 | 27 | ||
28 | // Ain't it a good place to fflush(NULL)? | 28 | fflush_all(); |
29 | 29 | ||
30 | /* Be nice to nommu machines. */ | 30 | /* Be nice to nommu machines. */ |
31 | failed = 0; | 31 | 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) | |||
255 | die_if_ferror(stdout, bb_msg_standard_output); | 255 | die_if_ferror(stdout, bb_msg_standard_output); |
256 | } | 256 | } |
257 | 257 | ||
258 | // Die with an error message if we have trouble flushing stdout. | 258 | int FAST_FUNC fflush_all(void) |
259 | void FAST_FUNC xfflush_stdout(void) | ||
260 | { | 259 | { |
261 | if (fflush(stdout)) { | 260 | return fflush(NULL); |
262 | bb_perror_msg_and_die(bb_msg_standard_output); | ||
263 | } | ||
264 | } | 261 | } |
265 | 262 | ||
266 | 263 | ||
@@ -276,9 +273,9 @@ int FAST_FUNC bb_putchar(int ch) | |||
276 | * then close that file. */ | 273 | * then close that file. */ |
277 | void FAST_FUNC xprint_and_close_file(FILE *file) | 274 | void FAST_FUNC xprint_and_close_file(FILE *file) |
278 | { | 275 | { |
279 | fflush(stdout); | 276 | fflush_all(); |
280 | // copyfd outputs error messages for us. | 277 | // copyfd outputs error messages for us. |
281 | if (bb_copyfd_eof(fileno(file), 1) == -1) | 278 | if (bb_copyfd_eof(fileno(file), STDOUT_FILENO) == -1) |
282 | xfunc_die(); | 279 | xfunc_die(); |
283 | 280 | ||
284 | fclose(file); | 281 | fclose(file); |