free(lpath);
} else { /* S_ISREG */
int fd = xopen(name, O_RDONLY);
- fflush(stdout);
+ fflush_all();
/* We must abort if file got shorter too! */
bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
bytes += st.st_size;
memset(&Z, 0, sizeof(Z));
INIT_G();
- //fflush(NULL); - is this needed because of NOEXEC?
+ //fflush_all(); - is this needed because of NOEXEC?
for (n = 1; argv[n]; n++) {
int what;
puts(dirname(argv[1]));
- return fflush(stdout);
+ return fflush_all();
}
bb_putchar('\n');
}
ret:
- return fflush(stdout);
+ return fflush_all();
}
/*-
printf("%lx\n", gethostid());
- return fflush(stdout);
+ return fflush_all();
}
printf("%u\n", (unsigned)strlen(*argv));
- return fflush(stdout);
+ return fflush_all();
}
/* Using _r function - avoid pulling in static buffer from libc */
if (getlogin_r(buf, sizeof(buf)) == 0) {
puts(buf);
- return fflush(stdout);
+ return fflush_all();
}
bb_perror_msg_and_die("getlogin");
if (buf != NULL) {
puts(buf);
free(buf);
- return fflush(stdout);
+ return fflush_all();
}
return EXIT_FAILURE;
if (n) /* if while loop executed at least once */
bb_putchar('\n');
- return fflush(stdout);
+ return fflush_all();
}
/* Will complain and die if username not found */
puts(xuid2uname(geteuid()));
- return fflush(stdout);
+ return fflush_all();
}
break;
case F_sy:
- fflush(NULL);
+ fflush_all();
R.d = (ENABLE_FEATURE_ALLOW_EXEC && L.s && *L.s)
? (system(L.s) >> 8) : 0;
break;
X.rsm = newfile(L.s);
fflush(X.rsm->F);
} else {
- fflush(NULL);
+ fflush_all();
}
}
break;
outfile = stderr;
/* There may have been output to stdout (option -l), so
* make sure we fflush before writing to stderr. */
- xfflush_stdout();
+ fflush_all();
}
if (!(opt & CMP_OPT_s)) {
if (opt & CMP_OPT_l) {
cc = 0;
printf("\"%s\", ", file);
- fflush(stdout);
+ fflush_all();
do {
cp = memchr(bufPtr, '\n', bufUsed);
}
printf("\"%s\", ", file);
- fflush(stdout);
+ fflush_all();
lp = findLine(num1);
if (lp == NULL) {
static void cookmode(void)
{
- fflush(stdout);
+ fflush_all();
tcsetattr_stdin_TCSANOW(&term_orig);
}
{
int c;
- fflush(stdout);
+ fflush_all();
c = read_key(STDIN_FILENO, readbuffer);
if (c == -1) { // EOF/error
go_bottom_and_clear_to_eol();
}
place_cursor(crow, ccol, FALSE); // put cursor back in correct place
}
- fflush(stdout);
+ fflush_all();
}
//----- format the status buffer, the bottom line of screen ------
if (msg[0]) {
printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
totalcmds, last_input_char, msg, SOs, SOn);
- fflush(stdout);
+ fflush_all();
while (safe_read(STDIN_FILENO, d, 1) > 0) {
if (d[0] == '\n' || d[0] == '\r')
break;
tty_stream = xfopen_for_read(CURRENT_TTY);
fputs(" ?...", stderr);
- fflush(stderr);
+ fflush_all();
c = savec = getc(tty_stream);
while (c != EOF && c != '\n')
c = getc(tty_stream);
extern void die_if_ferror(FILE *file, const char *msg) FAST_FUNC;
extern void die_if_ferror_stdout(void) FAST_FUNC;
-extern void xfflush_stdout(void) FAST_FUNC;
+extern int fflush_all(void) FAST_FUNC;
extern void fflush_stdout_and_exit(int retval) NORETURN FAST_FUNC;
extern int fclose_if_not_stdin(FILE *file) FAST_FUNC;
extern FILE *xfopen(const char *filename, const char *mode) FAST_FUNC;
}
fputs(prompt, stdout);
- fflush(stdout);
+ fflush_all();
ret = NULL;
/* On timeout or Ctrl-C, read will hopefully be interrupted,
* and we return NULL */
tcsetattr_stdin_TCSANOW(&oldtio);
bb_putchar('\n');
- fflush(stdout);
+ fflush_all();
return ret;
}
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);
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.
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
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();
}
}
) {
/* 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
};
int32_t ic, ic_raw;
- fflush(NULL);
+ fflush_all();
ic = ic_raw = lineedit_read_key(read_key_buffer);
#if ENABLE_FEATURE_EDITING_VI
tcsetattr_stdin_TCSANOW(&initial_settings);
/* restore SIGWINCH handler */
signal(SIGWINCH, previous_SIGWINCH_handler);
- fflush(NULL);
+ fflush_all();
len = command_len;
DEINIT_S();
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);
}
fputs(outbuf, stdout);
}
fclose(fp);
- fflush(stdout);
+ fflush_all();
}
void FAST_FUNC print_login_prompt(void)
fputs(hostname, stdout);
fputs(LOGIN, stdout);
- fflush(stdout);
+ fflush_all();
free(hostname);
}
}
if (logmode & LOGMODE_STDIO) {
- fflush(stdout);
+ fflush_all();
full_write(STDERR_FILENO, msg, used);
}
if (logmode & LOGMODE_SYSLOG) {
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);
volatile int failed;
pid_t pid;
-// Ain't it a good place to fflush(NULL)?
+ fflush_all();
/* Be nice to nommu machines. */
failed = 0;
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);
}
* 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);
puts("\r\nSystem closed for routine maintenance\r");
fclose(fp);
- fflush(NULL);
+ fflush_all();
/* Users say that they do need this prior to exit: */
tcdrain(STDOUT_FILENO);
exit(EXIT_FAILURE);
fd = open(bb_path_motd_file, O_RDONLY);
if (fd >= 0) {
- fflush(stdout);
+ fflush_all();
bb_copyfd_eof(fd, STDOUT_FILENO);
close(fd);
}
* We don't want to block here */
ndelay_on(1);
printf("\r\nLogin timed out after %d seconds\r\n", TIMEOUT);
- fflush(NULL);
+ fflush_all();
/* unix API is brain damaged regarding O_NONBLOCK,
* we should undo it, or else we can affect other processes */
ndelay_off(1);
msg = xasprintf(fmt, param);
printf("%s\r\n", msg);
}
- fflush(stdout);
+ fflush_all();
return msg;
}
printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
(unsigned)meminfo->erasesize / 1024, erase->start,
(unsigned long long) erase->start * 100 / meminfo->size);
- fflush(stdout);
+ fflush_all();
}
int flash_eraseall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
} else { /* Time device */
printf("Timing buffered disk reads:");
}
- fflush(stdout);
+ fflush_all();
/* Now do the timing */
iterations = 0;
/* Reset terminal input to normal */
static void set_tty_cooked(void)
{
- fflush(stdout);
+ fflush_all();
tcsetattr(kbd_fd, TCSANOW, &term_orig);
}
/* Position cursor if line input is done */
if (less_gets_pos >= 0)
move_cursor(max_displayed_line + 2, less_gets_pos + 1);
- fflush(stdout);
+ fflush_all();
if (kbd_input[0] == 0) { /* if nothing is buffered */
#if ENABLE_FEATURE_LESS_WINCH
} else {
printf(" UNSOLICITED?\n");
}
- fflush(stdout);
+ fflush_all();
}
received++;
if (FROM->sll_pkttype != PACKET_HOST)
cwd = xrealloc_getcwd_or_warn(NULL);
xpiped_pair(outfd);
- /*fflush(NULL); - so far we dont use stdio on output */
+ /*fflush_all(); - so far we dont use stdio on output */
pid = BB_MMU ? fork() : vfork();
if (pid < 0)
bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork");
pid_t child;
int status;
- fflush(NULL);
+ fflush_all();
child = vfork();
switch (child) {
case -1: /* failure */
xpiped_pair(infd);
xpiped_pair(outfd);
- fflush(NULL);
+ fflush_all();
pid = vfork();
switch (pid) {
}
}
bb_putchar('\n');
- /*fflush(stdout);*/
+ /*fflush_all();*/
return 0;
}
printf(" %s", buf);
}
bb_putchar('\n');
- /*fflush(stdout);*/
+ /*fflush_all();*/
return 0;
}
fputs(rtnl_rtntype_n2a(r->rtm_type, b1), stdout);
bb_putchar('\n');
- /*fflush(stdout);*/
+ /*fflush_all();*/
return 0;
}
/* Debug: squirt whatever message and sleep a bit so we can see it go by. */
/* Beware: writes to stdOUT... */
#if 0
-#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush(stdout); sleep(1); } while (0)
+#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush_all(); sleep(1); } while (0)
#else
#define Debug(...) do { } while (0)
#endif
if (tp)
printf(" time=%u.%03u ms", triptime / 1000, triptime % 1000);
puts(dupmsg);
- fflush(stdout);
+ fflush_all();
}
static void unpack4(char *buf, int sz, struct sockaddr_in *from)
{
/*ts->size2 = 0;*/
}
- fflush(NULL); /* flush all streams */
+ fflush_all();
pid = vfork(); /* NOMMU-friendly */
if (pid < 0) {
free(ts);
/*termbuf.c_lflag &= ~ICANON;*/
tcsetattr_stdin_TCSANOW(&termbuf);
- /* Uses FILE-based I/O to stdout, but does fflush(stdout),
+ /* Uses FILE-based I/O to stdout, but does fflush_all(),
* so should be safe with vfork.
* I fear, though, that some users will have ridiculously big
* issue files, and they may block writing to fd 1,
if (!first && pausemsecs > 0)
usleep(pausemsecs * 1000);
- fflush(stdout);
+ fflush_all();
t1 = monotonic_us();
send_probe(++seq, ttl);
}
/* printf(" %d", hist_iterations); */
bb_putchar(OPT_BATCH_MODE ? '\n' : '\r');
- fflush(stdout);
+ fflush_all();
}
#undef UPSCALE
#undef SHOW_STAT
s++;
}
bb_putchar(OPT_BATCH_MODE ? '\n' : '\r');
- fflush(stdout);
+ fflush_all();
#undef HDR_STR
#undef MIN_WIDTH
}
puts(header);
}
- fflush(stdout);
+ fflush_all();
// TODO: 'real' watch pipes cmd's output to itself
// and does not allow it to overflow the screen
// (taking into account linewrap!)
/* Move unprocessed data to the front of line */
memmove((timestamp ? line+26 : line), lineptr, stdin_cnt);
}
- fflush(NULL);////
+ fflush_all();////
}
for (i = 0; i < dirn; ++i) {
putchar('\n');
}
ret:
- return fflush(stdout);
+ return fflush_all();
}
/*-
if (count == 0)
bb_putchar('\n');
bb_putchar('*');
- fflush(stdout);
+ fflush_all();
}
}
flush_stdout_stderr(void)
{
INT_OFF;
- fflush(stdout);
- fflush(stderr);
- INT_ON;
-}
-
-static void
-flush_stderr(void)
-{
- INT_OFF;
- fflush(stderr);
+ fflush_all();
INT_ON;
}
out2str(const char *p)
{
outstr(p, stderr);
- flush_stderr();
+ flush_stdout_stderr();
}
default:
#if DEBUG
out1fmt("Node type = %d\n", n->type);
- fflush(stdout);
+ fflush_all();
break;
#endif
case NNOT:
for (;;) {
find_command(argv[0], &cmdentry, cmd_flag, path);
if (cmdentry.cmdtype == CMDUNKNOWN) {
- flush_stderr();
+ flush_stdout_stderr();
status = 127;
goto bail;
}
}
#if ENABLE_HUSH_JOB
- fflush(NULL); /* flush all streams */
+ fflush_all();
sigexit(- (exitcode & 0xff));
#else
exit(exitcode);
do {
G.flag_SIGINT = 0;
fputs(prompt_str, stdout);
- fflush(stdout);
+ fflush_all();
G.user_input_buf[0] = r = fgetc(i->file);
/*G.user_input_buf[1] = '\0'; - already is and never changed */
//do we need check_and_run_traps(0)? (maybe only if stdin)
G.global_argc = n;
/* On MMU, funcp->body is always non-NULL */
n = run_list(funcp->body);
- fflush(NULL);
+ fflush_all();
_exit(n);
# else
re_execute_shell(to_free,
{
#if BB_MMU
int rcode = x->function(argv);
- fflush(NULL);
+ fflush_all();
_exit(rcode);
#else
/* On NOMMU, we must never block!
debug_printf_exec(": builtin '%s' '%s'...\n",
x->cmd, argv_expanded[1]);
rcode = x->function(argv_expanded) & 0xff;
- fflush(NULL);
+ fflush_all();
}
#if ENABLE_HUSH_FUNCTIONS
else {
putchar('\n');
#endif
}
- /*fflush(stdout); - done after each builtin anyway */
+ /*fflush_all(); - done after each builtin anyway */
}
return EXIT_SUCCESS;
}
printf(" %s\n", get_signame(i));
}
}
- /*fflush(stdout); - done after each builtin anyway */
+ /*fflush_all(); - done after each builtin anyway */
return EXIT_SUCCESS;
}
} else { /* logread -f */
if (cur == shbuf_tail) {
sem_up(log_semid);
- fflush(stdout);
+ fflush_all();
sleep(1); /* TODO: replace me with a sleep_on */
continue;
}
}
printf(def ? "%s (y/n)? " : "%s (n/y)? ", string);
for (;;) {
- fflush(NULL);
+ fflush_all();
c = getchar();
if (c == EOF) {
if (!def)
if (!G.currently_testing)
return;
printf("%d ...", G.currently_testing);
- fflush(stdout);
+ fflush_all();
}
static void check_blocks(void)
(int) (ftello(file)*100 / st.st_size),
st.st_size);
}
- fflush(stdout);
+ fflush_all();
/*
* We've just displayed the "--More--" prompt, so now we need
putchar(c);
}
fclose(file);
- fflush(stdout);
+ fflush_all();
} while (*argv && *++argv);
end:
setTermSettings(cin_fileno, &initial_settings);
sync();
printf("wakeup from \"%s\" at %s", suspend, ctime(&alarm_time));
- fflush(NULL);
+ fflush_all();
usleep(10 * 1000);
if (strcmp(suspend, "on"))