introduce bb_putchar(). saves ~1800 on uclibc (less on glibc).

This commit is contained in:
Denis Vlasenko 2007-09-27 10:20:47 +00:00
parent 1acdc89e99
commit 4daad9004d
62 changed files with 208 additions and 210 deletions

View File

@ -686,7 +686,7 @@ static void check_match(IPos start, IPos match, int length)
if (verbose > 1) {
bb_error_msg("\\[%d,%d]", start - match, length);
do {
putc(G1.window[start++], stderr);
fputc(G1.window[start++], stderr);
} while (--length != 0);
}
}

View File

@ -26,6 +26,5 @@ void header_verbose_list(const file_header_t *file_header)
if (file_header->link_target) {
printf(" -> %s", file_header->link_target);
}
/* putchar isnt used anywhere else i dont think */
puts("");
bb_putchar('\n');
}

View File

@ -167,7 +167,7 @@ int cal_main(int argc, char **argv)
if (!julian) {
printf("%*s%s", HEAD_SEP, "", day_headings);
}
putchar('\n');
bb_putchar('\n');
for (row = 0; row < (6*7); row += 7) {
for (which_cal = 0; which_cal < 3-julian; which_cal++) {
dp = days[month + which_cal] + row;

View File

@ -62,13 +62,13 @@ int catv_main(int argc, char **argv)
if (c < 32) {
if (c == 10) {
if (flags & CATV_OPT_e)
putchar('$');
bb_putchar('$');
} else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
printf("^%c", c+'@');
continue;
}
}
putchar(c);
bb_putchar(c);
}
}
if (ENABLE_FEATURE_CLEAN_UP && fd)

View File

@ -100,18 +100,18 @@ int bb_echo(char **argv)
c = bb_process_escape_sequence(&arg);
}
}
putchar(c);
bb_putchar(c);
}
arg = *++argv;
if (!arg)
break;
putchar(' ');
bb_putchar(' ');
}
newline_ret:
if (nflag) {
putchar('\n');
bb_putchar('\n');
}
ret:
return fflush(stdout);

View File

@ -115,7 +115,7 @@ int fold_main(int argc, char **argv)
/* Found a blank. Don't output the part after it. */
logical_end++;
fwrite(line_out, sizeof(char), (size_t) logical_end, stdout);
putchar('\n');
bb_putchar('\n');
/* Move the remainder to the beginning of the next line.
The areas being copied here might overlap. */
memmove(line_out, line_out + logical_end, offset_out - logical_end);

View File

@ -102,7 +102,7 @@ int id_main(int argc, char **argv)
/* Print full info like GNU id */
/* bb_getpwuid(0) doesn't exit on failure (returns NULL) */
status = printf_full(uid, bb_getpwuid(NULL, 0, uid), 'u');
putchar(' ');
bb_putchar(' ');
status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), 'g');
#if ENABLE_SELINUX
@ -121,6 +121,6 @@ int id_main(int argc, char **argv)
}
#endif
putchar('\n');
bb_putchar('\n');
fflush_stdout_and_exit(status);
}

View File

@ -451,7 +451,7 @@ static void showdirs(struct dnode **dn, int ndirs, int first)
for (i = 0; i < ndirs; i++) {
if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
if (!first)
puts("");
bb_putchar('\n');
first = 0;
printf("%s:\n", dn[i]->fullname);
}

View File

@ -1183,7 +1183,7 @@ dump_strings(void)
case '\r': fputs("\\r", stdout); break;
case '\t': fputs("\\t", stdout); break;
case '\v': fputs("\\v", stdout); break;
default: putc(c, stdout);
default: bb_putchar(c);
}
}
putchar('\n');

View File

@ -99,9 +99,9 @@ static void print_esc_string(char *str)
for (; *str; str++) {
if (*str == '\\') {
str++;
putchar(bb_process_escape_sequence((const char **)&str));
bb_putchar(bb_process_escape_sequence((const char **)&str));
} else {
putchar(*str);
bb_putchar(*str);
}
}
@ -205,7 +205,7 @@ static int print_formatted(char *format, int argc, char **argv)
direc_length = 1;
field_width = precision = -1;
if (*f == '%') {
putchar('%');
bb_putchar('%');
break;
}
if (*f == 'b') {
@ -274,11 +274,11 @@ static int print_formatted(char *format, int argc, char **argv)
case '\\':
if (*++f == 'c')
exit(0);
putchar(bb_process_escape_sequence((const char **)&f));
bb_putchar(bb_process_escape_sequence((const char **)&f));
f--;
break;
default:
putchar(*f);
bb_putchar(*f);
}
}

View File

@ -321,7 +321,7 @@ static void print_it(char const *masterformat, char const *filename,
b = NULL;
/* fall through */
case '%':
putchar('%');
bb_putchar('%');
break;
default:
print_func(dest, n_alloc, *p, filename, data USE_SELINUX(,scontext));
@ -552,7 +552,7 @@ static bool do_stat(char const *filename, char const *format)
if (option_mask32 & OPT_SELINUX)
printf(" %lc\n", *scontext);
else
putchar('\n');
bb_putchar('\n');
#endif
} else {
char *linkname = NULL;
@ -586,7 +586,7 @@ static bool do_stat(char const *filename, char const *format)
(unsigned long) major(statbuf.st_rdev),
(unsigned long) minor(statbuf.st_rdev));
else
putchar('\n');
bb_putchar('\n');
printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n",
(unsigned long) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)),
bb_mode_string(statbuf.st_mode),

View File

@ -475,10 +475,10 @@ static void wrapf(const char *message, ...)
G.current_col++;
if (buf[0] != '\n') {
if (G.current_col + buflen >= max_col) {
putchar('\n');
bb_putchar('\n');
G.current_col = 0;
} else
putchar(' ');
bb_putchar(' ');
}
}
fputs(buf, stdout);
@ -618,7 +618,7 @@ static void display_recoverable(const struct termios *mode,
(unsigned long) mode->c_cflag, (unsigned long) mode->c_lflag);
for (i = 0; i < NCCS; ++i)
printf(":%x", (unsigned int) mode->c_cc[i]);
putchar('\n');
bb_putchar('\n');
}
static void display_speed(const struct termios *mode, int fancy)

View File

@ -22,6 +22,7 @@ int tee_main(int argc, char **argv)
char **names;
char **np;
char retval;
//TODO: make unconditional
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
ssize_t c;
# define buf bb_common_bufsiz1
@ -62,7 +63,7 @@ int tee_main(int argc, char **argv)
/* names[0] will be filled later */
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
while ((c = safe_read(STDIN_FILENO, buf, BUFSIZ)) > 0) {
while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
fp = files;
do
fwrite(buf, 1, c, *fp++);

View File

@ -91,12 +91,12 @@ int uname_main(int argc, char **argv)
if (toprint & 1) {
printf(((char *)(&uname_info)) + *delta);
if (toprint > 1) {
putchar(' ');
bb_putchar(' ');
}
}
++delta;
} while (toprint >>= 1);
putchar('\n');
bb_putchar('\n');
fflush_stdout_and_exit(EXIT_SUCCESS);
}

View File

@ -48,9 +48,9 @@ int uuencode_main(int argc, char **argv)
bb_perror_msg_and_die(bb_msg_read_error);
/* Encode the buffer we just read in */
bb_uuencode(dst_buf, src_buf, size, tbl);
putchar('\n');
bb_putchar('\n');
if (tbl == bb_uuenc_tbl_std) {
putchar(tbl[size]);
bb_putchar(tbl[size]);
}
fflush(stdout);
xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3));

View File

@ -651,7 +651,7 @@ static void execute(const char *type, const char *device, const char *mntpt,
mntpt ? mntpt : device);
for (i = 0; i < argc; i++)
printf(" %s", argv[i]);
puts("");
bb_putchar('\n');
}
/* Fork and execute the correct program. */

View File

@ -46,7 +46,7 @@ static void list_attributes(const char *name)
if (option_mask32 & OPT_PF_LONG) {
printf("%-28s ", name);
print_flags(stdout, fsflags, PFOPT_LONG);
puts("");
bb_putchar('\n');
} else {
print_flags(stdout, fsflags, 0);
printf(" %s\n", name);
@ -74,7 +74,7 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
) {
printf("\n%s:\n", path);
iterate_on_dir(path, lsattr_dir_proc, NULL);
puts("");
bb_putchar('\n');
}
}

View File

@ -82,7 +82,7 @@ void blkid_debug_dump_dev(blkid_dev dev)
else
printf(" tag: NULL\n");
}
puts("");
bb_putchar('\n');
}
#endif

View File

@ -436,7 +436,7 @@ static void debug_dump_dev(blkid_dev dev)
else
printf(" tag: NULL\n");
}
puts("");
bb_putchar('\n');
}
int main(int argc, char**argv)

View File

@ -2443,10 +2443,10 @@ static void safe_print(const char *cp, int len)
ch -= 128;
}
if ((ch < 32) || (ch == 0x7f)) {
fputc('^', stdout);
bb_putchar('^');
ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
}
fputc(ch, stdout);
bb_putchar(ch);
}
}
@ -2497,7 +2497,7 @@ static void expand_at_expression(e2fsck_t ctx, char ch,
str = _(*cpp) + 1;
if (*first && islower(*str)) {
*first = 0;
fputc(toupper(*str++), stdout);
bb_putchar(toupper(*str++));
}
print_e2fsck_message(ctx, str, pctx, *first);
} else
@ -2630,7 +2630,7 @@ static void expand_percent_expression(ext2_filsys fs, char ch,
switch (ch) {
case '%':
fputc('%', stdout);
bb_putchar('%');
break;
case 'b':
printf("%u", ctx->blk);
@ -12767,7 +12767,7 @@ static void check_if_skip(e2fsck_t ctx)
else
printf(_(" (check in %ld mounts)"), next_check);
}
fputc('\n', stdout);
bb_putchar('\n');
ext2fs_close(fs);
ctx->fs = NULL;
e2fsck_free_context(ctx);
@ -12864,9 +12864,9 @@ int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent,
bar + (sizeof(bar) - (i+1)),
spaces + (sizeof(spaces) - (dpywidth - i + 1)));
if (fixed_percent == 1000)
fputc('|', stdout);
bb_putchar('|');
else
fputc(spinner[ctx->progress_pos & 3], stdout);
bb_putchar(spinner[ctx->progress_pos & 3]);
printf(" %4.1f%% ", percent);
if (dpynum)
printf("%u\r", dpynum);

View File

@ -613,7 +613,7 @@ static int execute(const char *type, const char *device, const char *mntpt,
mntpt ? mntpt : device);
for (i=0; i < argc; i++)
printf("%s ", argv[i]);
puts("");
bb_putchar('\n');
}
/* Fork and execute the correct program. */

View File

@ -57,7 +57,7 @@ static void list_attributes(const char *name)
if (flags & OPT_PF_LONG) {
printf("%-28s ", name);
print_flags(stdout, fsflags, PFOPT_LONG);
puts("");
bb_putchar('\n');
} else {
print_flags(stdout, fsflags, 0);
printf(" %s\n", name);
@ -102,7 +102,7 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
(de->d_name[1] != '.' && de->d_name[2] != '\0')))) {
printf("\n%s:\n", path);
iterate_on_dir(path, lsattr_dir_proc, NULL);
puts("");
bb_putchar('\n');
}
}
}

View File

@ -641,7 +641,7 @@ static void show_stats(ext2_filsys fs)
s->s_blocks_per_group, s->s_frags_per_group,
s->s_inodes_per_group);
if (fs->group_desc_count == 1) {
puts("");
bb_putchar('\n');
return;
}

View File

@ -147,7 +147,7 @@ main(int argc, char **argv)
printf(" (random)\n");
break;
default:
puts("");
bb_putchar('\n');
}
if (type != 1) {
printf("Warning: not a time-based UUID, so UUID time "

View File

@ -853,14 +853,14 @@ static int printLines(int num1, int num2, int expandFlag)
ch &= 0x7f;
}
if (ch < ' ') {
fputc('^', stdout);
bb_putchar('^');
ch += '@';
}
if (ch == 0x7f) {
fputc('^', stdout);
bb_putchar('^');
ch = '?';
}
fputc(ch, stdout);
bb_putchar(ch);
}
fputs("$\n", stdout);

View File

@ -868,13 +868,13 @@ static void colon(char * buf)
if (c == '\n') {
write1("$\r");
} else if (c < ' ' || c == 127) {
putchar('^');
bb_putchar('^');
if (c == 127)
c = '?';
else
c += '@';
}
putchar(c);
bb_putchar(c);
if (c_is_no_print)
standout_end();
}
@ -2337,7 +2337,7 @@ static char *get_input_line(const char * prompt) // get input line- use "status
} else {
buf[i] = c; // save char in buffer
buf[i + 1] = '\0'; // make sure buffer is null terminated
putchar(c); // echo the char back to user
bb_putchar(c); // echo the char back to user
i++;
}
}
@ -2860,7 +2860,7 @@ static void refresh(int full_screen)
char *out = sp + cs;
while (nic-- > 0) {
putchar(*out);
bb_putchar(*out);
out++;
}
}

View File

@ -391,11 +391,13 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
struct sockaddr *from, struct sockaddr *to,
socklen_t sa_size);
extern char *xstrdup(const char *s);
extern char *xstrndup(const char *s, int n);
extern char *safe_strncpy(char *dst, const char *src, size_t size);
extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
char *xstrdup(const char *s);
char *xstrndup(const char *s, int n);
char *safe_strncpy(char *dst, const char *src, size_t size);
/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc.
/* But potentially slow, don't use in one-billion-times loops */
int bb_putchar(int ch);
char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
// gcc-4.1.1 still isn't good enough at optimizing it
// (+200 bytes compared to macro)
//static ALWAYS_INLINE

View File

@ -69,7 +69,7 @@ char *bb_askpass(int timeout, const char * prompt)
}
tcsetattr(STDIN_FILENO, TCSANOW, &old);
putchar('\n');
bb_putchar('\n');
fflush(stdout);
return ret;
}

View File

@ -111,15 +111,15 @@ static void cmdedit_set_out_char(int next_char)
#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 @@ static void goto_new_line(void)
{
input_end();
if (cmdedit_x)
putchar('\n');
bb_putchar('\n');
}
@ -149,7 +149,7 @@ static void out1str(const char *s)
static void beep(void)
{
putchar('\007');
bb_putchar('\007');
}
/* Move back one character */
@ -197,7 +197,7 @@ static void redraw(int y, int back_cursor)
{
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 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t
beep();
else {
*(command + cursor) = c;
putchar(c);
putchar('\b');
bb_putchar(c);
bb_putchar('\b');
}
break;
#endif /* FEATURE_COMMAND_EDITING_VI */

View File

@ -456,6 +456,14 @@ off_t fdlength(int fd)
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, ...)

View File

@ -125,7 +125,7 @@ static void die_if_nologin_and_non_root(int amroot)
fp = fopen("/etc/nologin", "r");
if (fp) {
while ((c = getc(fp)) != EOF)
putchar((c=='\n') ? '\r' : c);
bb_putchar((c=='\n') ? '\r' : c);
fflush(stdout);
fclose(fp);
} else

View File

@ -482,19 +482,43 @@ static void print_value_on_off(const char *str, unsigned long argp)
}
#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
static void print_ascii(uint16_t *p, uint8_t length);
static void print_ascii(const char *p, int length)
{
#if BB_BIG_ENDIAN
#define LE_ONLY(x)
enum { ofs = 0 };
#else
#define LE_ONLY(x) x
/* every 16bit word is big-endian (i.e. inverted) */
/* accessing bytes in 1,0, 3,2, 5,4... sequence */
int ofs = 1;
#endif
length *= 2;
/* find first non-space & print it */
while (length && p[ofs] != ' ') {
p++;
LE_ONLY(ofs = -ofs;)
length--;
}
while (length && p[ofs]) {
bb_putchar(p[ofs]);
p++;
LE_ONLY(ofs = -ofs;)
length--;
}
bb_putchar('\n');
#undef LE_ONLY
}
static void xprint_ascii(uint16_t *val, int i, const char *string, int n)
{
if (val[i]) {
printf("\t%-20s", string);
print_ascii(&val[i], n);
print_ascii((void*)&val[i], n);
}
}
#endif
/* end of busybox specific stuff */
#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
{
uint16_t ii;
@ -515,41 +539,11 @@ static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *
return err_dma;
}
static void print_ascii(uint16_t *p, uint8_t length)
{
uint8_t ii;
char cl;
/* find first non-space & print it */
for (ii = 0; ii < length; ii++) {
if ((char)((*p)>>8) != ' ')
break;
cl = (char)(*p);
if (cl != ' ') {
if (cl != '\0')
printf("%c", cl);
p++;
ii++;
break;
}
p++;
}
/* print the rest */
for (; ii< length; ii++) {
if (!(*p))
break; /* some older devices have NULLs */
printf("%c%c", (char)((*p)>>8), (char)(*p));
p++;
}
puts("");
}
// Parse 512 byte disk identification block and print much crap.
static void identify(uint16_t *id_supplied)
static void identify(uint16_t *val)
{
uint16_t buf[256];
uint16_t *val, ii, jj, kk;
uint16_t ii, jj, kk;
uint16_t like_std = 1, std = 0, min_std = 0xffff;
uint16_t dev = NO_DEV, eqpt = NO_DEV;
uint8_t have_mode = 0, err_dma = 0;
@ -557,19 +551,15 @@ static void identify(uint16_t *id_supplied)
uint32_t ll, mm, nn, oo;
uint64_t bbbig; /* (:) */
const char *strng;
#if BB_BIG_ENDIAN
uint16_t buf[256];
// Adjust for endianness if necessary.
if (BB_BIG_ENDIAN) {
swab(id_supplied, buf, sizeof(buf));
val = buf;
} else
val = id_supplied;
chksum &= 0xff;
// Adjust for endianness
swab(val, buf, sizeof(buf));
val = buf;
#endif
/* check if we recognise the device type */
puts("");
bb_putchar('\n');
if (!(val[GEN_CONFIG] & NOT_ATA)) {
dev = ATA_DEV;
printf("ATA device, with ");
@ -686,7 +676,7 @@ static void identify(uint16_t *id_supplied)
else if (like_std > std)
printf("& some of %u\n", like_std);
else
puts("");
bb_putchar('\n');
} else {
/* TBD: do CDROM stuff more thoroughly. For now... */
kk = 0;
@ -786,7 +776,7 @@ static void identify(uint16_t *id_supplied)
if (bbbig > 1000)
printf("(%"PRIu64" GB)\n", bbbig/1000);
else
puts("");
bb_putchar('\n');
}
/* hw support of commands (capabilities) */
@ -829,7 +819,7 @@ static void identify(uint16_t *id_supplied)
if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
printf(", %s device specific minimum\n", (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no");
else
puts("");
bb_putchar('\n');
}
printf("\tR/W multiple sector transfer: ");
if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
@ -866,7 +856,7 @@ static void identify(uint16_t *id_supplied)
printf("\tOverlap support:");
if (val[PKT_REL]) printf(" %uus to release bus.", val[PKT_REL]);
if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.", val[SVC_NBSY]);
puts("");
bb_putchar('\n');
}
}
@ -893,7 +883,7 @@ static void identify(uint16_t *id_supplied)
err_dma += mode_loop(jj, kk, 'u', &have_mode);
}
if (err_dma || !have_mode) printf("(?)");
puts("");
bb_putchar('\n');
if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP))
printf("\t\tInterleaved DMA support\n");
@ -904,7 +894,7 @@ static void identify(uint16_t *id_supplied)
printf("\t\tCycle time:");
if (val[DMA_TIME_MIN]) printf(" min=%uns", val[DMA_TIME_MIN]);
if (val[DMA_TIME_NORM]) printf(" recommended=%uns", val[DMA_TIME_NORM]);
puts("");
bb_putchar('\n');
}
}
@ -918,11 +908,11 @@ static void identify(uint16_t *id_supplied)
if (jj & 0x0001) printf("pio%d ", ii);
jj >>=1;
}
puts("");
bb_putchar('\n');
} else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE)) {
for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
printf("pio%d ", ii);
puts("");
bb_putchar('\n');
} else
printf("unknown\n");
@ -931,7 +921,7 @@ static void identify(uint16_t *id_supplied)
printf("\t\tCycle time:");
if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]);
if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]);
puts("");
bb_putchar('\n');
}
}
@ -982,7 +972,7 @@ static void identify(uint16_t *id_supplied)
printf("\t");
if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, "");
if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED ");
puts("");
bb_putchar('\n');
}
}
@ -1134,7 +1124,7 @@ static void dump_identity(const struct hd_driveid *id)
else
printf("off");
}
puts("");
bb_putchar('\n');
if (!(id->field_valid & 1))
printf(" (maybe):");
@ -1905,7 +1895,7 @@ static void parse_xfermode(int flag, smallint *get, smallint *set, int *value)
/*------- getopt short options --------*/
static const char hdparm_options[] ALIGN1 =
"gfu::n::p:r::m::c::k::a::B:tTh"
"gfu::n::p:r::m::c::k::a::B:tT"
USE_FEATURE_HDPARM_GET_IDENTITY("iI")
USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::")
#ifdef HDIO_DRIVE_CMD
@ -1933,7 +1923,6 @@ int hdparm_main(int argc, char **argv)
while ((c = getopt(argc, argv, hdparm_options)) >= 0) {
flagcount++;
if (c == 'h') bb_show_usage(); /* EXIT */
USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I'));
USE_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i'));
get_geom |= (c == 'g');
@ -1999,7 +1988,7 @@ int hdparm_main(int argc, char **argv)
if (!*argv) {
if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO))
identify_from_stdin(); /* EXIT */
else bb_show_usage();
bb_show_usage();
}
do {

View File

@ -173,7 +173,7 @@ static void less_exit(int code)
* and restore it when we exit. Less does this with the
* "ti" and "te" termcap commands; can this be done with
* only termios.h? */
putchar('\n');
bb_putchar('\n');
fflush_stdout_and_exit(code);
}
@ -419,7 +419,7 @@ static void status_print(void)
clear_line();
if (cur_fline && cur_fline < max_fline - max_displayed_line) {
putchar(':');
bb_putchar(':');
return;
}
p = "(END)";
@ -755,7 +755,7 @@ static char* less_gets(int sz)
continue;
if (i >= width - sz - 1)
continue; /* len limit */
putchar(c);
bb_putchar(c);
result[i++] = c;
result = xrealloc(result, i+1);
result[i] = '\0';
@ -916,7 +916,7 @@ static void regex_process(void)
/* Get the uncompiled regular expression from the user */
clear_line();
putchar((option_mask32 & LESS_STATE_MATCH_BACKWARDS) ? '?' : '/');
bb_putchar((option_mask32 & LESS_STATE_MATCH_BACKWARDS) ? '?' : '/');
uncomp_regex = less_gets(1);
if (!uncomp_regex[0]) {
free(uncomp_regex);
@ -969,7 +969,7 @@ static void number_process(int first_digit)
num_input[i] = less_getch();
if (!num_input[i] || !isdigit(num_input[i]))
break;
putchar(num_input[i]);
bb_putchar(num_input[i]);
i++;
}
@ -1024,7 +1024,7 @@ static void flag_change(void)
int keypress;
clear_line();
putchar('-');
bb_putchar('-');
keypress = less_getch();
switch (keypress) {
@ -1049,7 +1049,7 @@ static void show_flag_status(void)
int flag_val;
clear_line();
putchar('_');
bb_putchar('_');
keypress = less_getch();
switch (keypress) {

View File

@ -34,7 +34,7 @@ int mountpoint_main(int argc, char **argv)
return EXIT_SUCCESS;
} else {
if (opt & OPT_q)
putchar('\n');
bb_putchar('\n');
else
bb_error_msg("%s: not a block device", arg);
}

View File

@ -56,7 +56,7 @@ int strings_main(int argc, char **argv)
c = fgetc(file);
if (isprint(c) || c == '\t') {
if (count > n) {
putchar(c);
bb_putchar(c);
} else {
string[count] = c;
if (count == n) {
@ -72,7 +72,7 @@ int strings_main(int argc, char **argv)
}
} else {
if (count > n) {
putchar('\n');
bb_putchar('\n');
}
count = 0;
}

View File

@ -188,8 +188,6 @@ static void summarize(const char *fmt, char **command, resource_t * resp)
#endif
if (!cpu_ticks) cpu_ticks = 1; /* we divide by it, must be nonzero */
/* putchar() != putc(stdout) in glibc! */
while (*fmt) {
/* Handle leading literal part */
int n = strcspn(fmt, "%\\");
@ -205,7 +203,7 @@ static void summarize(const char *fmt, char **command, resource_t * resp)
/* Usually we optimize for size, but there is a limit
* for everything. With this we do a lot of 1-byte writes */
default:
putc(*fmt, stdout);
bb_putchar(*fmt);
break;
#endif
@ -215,11 +213,11 @@ static void summarize(const char *fmt, char **command, resource_t * resp)
/* Our format strings do not have these */
/* and we do not take format str from user */
default:
putc('%', stdout);
bb_putchar('%');
/*FALLTHROUGH*/
case '%':
if (!*fmt) goto ret;
putc(*fmt, stdout);
bb_putchar(*fmt);
break;
#endif
case 'C': /* The command that got timed. */
@ -351,17 +349,17 @@ static void summarize(const char *fmt, char **command, resource_t * resp)
case '\\': /* Format escape. */
switch (*++fmt) {
default:
putc('\\', stdout);
bb_putchar('\\');
/*FALLTHROUGH*/
case '\\':
if (!*fmt) goto ret;
putc(*fmt, stdout);
bb_putchar(*fmt);
break;
case 't':
putc('\t', stdout);
bb_putchar('\t');
break;
case 'n':
putc('\n', stdout);
bb_putchar('\n');
break;
}
break;
@ -370,7 +368,7 @@ static void summarize(const char *fmt, char **command, resource_t * resp)
++fmt;
}
/* ret: */
putc('\n', stdout);
bb_putchar('\n');
}
/* Run command CMD and return statistics on it.
@ -437,6 +435,7 @@ int time_main(int argc, char **argv)
run_command(argv, &res);
/* Cheat. printf's are shorter :) */
/* (but see bb_putchar() body for additional wrinkle!) */
stdout = stderr;
dup2(2, 1); /* just in case libc does something silly :( */
summarize(output_format, argv, &res);

View File

@ -39,6 +39,6 @@ int ttysize_main(int argc, char **argv)
fmt = "%u %u" + 2; /* " %u" */
}
}
putchar('\n');
bb_putchar('\n');
return 0;
}

View File

@ -15,7 +15,7 @@
#if !ENABLE_FEATURE_CHECK_TAINTED_MODULE
static void check_tainted(void) { puts(""); }
static void check_tainted(void) { bb_putchar('\n'); }
#else
#define TAINT_FILENAME "/proc/sys/kernel/tainted"
#define TAINT_PROPRIETORY_MODULE (1<<0)
@ -128,7 +128,7 @@ int lsmod_main(int argc, char **argv)
}
if (count) printf("]");
puts("");
bb_putchar('\n');
}
#if ENABLE_FEATURE_CLEAN_UP
@ -178,7 +178,7 @@ int lsmod_main(int argc, char **argv)
}
printf(" %s", tok);
}
puts("");
bb_putchar('\n');
free(line);
}
fclose(file);

View File

@ -92,7 +92,7 @@ void bb_debug_dump_packet(unsigned char *outpack, int pktsize)
printf("packet dump:\n");
for (i = 0; i < pktsize; ++i) {
printf("%2.2x ", outpack[i]);
if (i % 20 == 19) puts("");
if (i % 20 == 19) bb_putchar('\n');
}
printf("\n\n");
}

View File

@ -83,7 +83,7 @@ int hostname_main(int argc, char **argv)
while (hp->h_addr_list[0]) {
printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++)));
}
puts("");
bb_putchar('\n');
}
}
/* Set the hostname */

View File

@ -1259,7 +1259,7 @@ int ifupdown_main(int argc, char **argv)
iface_list = iface_list->link;
}
if (VERBOSE) {
puts("");
bb_putchar('\n');
}
if (!okay && !FORCE) {

View File

@ -937,7 +937,7 @@ static void ife_print(struct interface *ptr)
printf("(auto)");
}
#endif
puts("");
bb_putchar('\n');
if (ptr->has_ip) {
printf(" %s addr:%s ", ap->name,
@ -1073,7 +1073,7 @@ static void ife_print(struct interface *ptr)
if (ptr->outfill || ptr->keepalive)
printf(" Outfill:%d Keepalive:%d", ptr->outfill, ptr->keepalive);
#endif
puts("");
bb_putchar('\n');
/* If needed, display the interface statistics. */
@ -1122,9 +1122,9 @@ static void ife_print(struct interface *ptr)
}
if (ptr->map.dma)
printf("DMA chan:%x ", ptr->map.dma);
puts("");
bb_putchar('\n');
}
puts("");
bb_putchar('\n');
}

View File

@ -482,7 +482,7 @@ static void do_tunnels_list(struct ip_tunnel_parm *p)
(p->i_key && p1.i_key != p->i_key))
continue;
print_tunnel(&p1);
puts("");
bb_putchar('\n');
}
}
@ -512,7 +512,7 @@ static int do_show(int argc, char **argv)
return -1;
print_tunnel(&p);
puts("");
bb_putchar('\n');
return 0;
}

View File

@ -112,7 +112,7 @@ static void server_print(void)
print_host(server, "Server:");
if (ENABLE_FEATURE_CLEAN_UP)
free(server);
puts("");
bb_putchar('\n');
}
/* alter the global _res nameserver structure to use

View File

@ -1322,7 +1322,7 @@ int traceroute_main(int argc, char **argv)
printf(" *");
(void)fflush(stdout);
}
putchar('\n');
bb_putchar('\n');
if (got_there ||
(unreachable > 0 && unreachable >= nprobes - 1))
break;

View File

@ -142,7 +142,7 @@ static void progressmeter(int flag)
/* last call to progressmeter */
alarm(0);
transferred = 0;
putc('\n', stderr);
fputc('\n', stderr);
} else {
if (flag == -1) {
/* first call to progressmeter */

View File

@ -292,7 +292,7 @@ static int fuser_print_pid_list(pid_list *plist)
printf("%d ", curr->pid);
curr = curr->next;
}
puts("");
bb_putchar('\n');
return 1;
}

View File

@ -76,7 +76,7 @@ int pidof_main(int argc, char **argv)
free(pidList);
optind++;
}
putchar('\n');
bb_putchar('\n');
#if ENABLE_FEATURE_PIDOF_OMIT
if (ENABLE_FEATURE_CLEAN_UP)

View File

@ -482,7 +482,7 @@ static NOINLINE void display_process_list(int count, int scr_width)
s++;
}
/* printf(" %d", hist_iterations); */
putchar(OPT_BATCH_MODE ? '\n' : '\r');
bb_putchar(OPT_BATCH_MODE ? '\n' : '\r');
fflush(stdout);
}
#undef UPSCALE
@ -752,7 +752,7 @@ static NOINLINE void display_topmem_process_list(int count, int scr_width)
printf("\n""%.*s", scr_width, line_buf);
s++;
}
putchar(OPT_BATCH_MODE ? '\n' : '\r');
bb_putchar(OPT_BATCH_MODE ? '\n' : '\r');
fflush(stdout);
#undef HDR_STR
#undef MIN_WIDTH
@ -972,6 +972,6 @@ int top_main(int argc, char **argv)
}
#endif /* FEATURE_USE_TERMIOS */
}
putchar('\n');
bb_putchar('\n');
return EXIT_SUCCESS;
}

View File

@ -179,7 +179,7 @@ static void out(const char *p, const char *m1)
if (errno) {
printf(": %s", strerror(errno));
}
puts(""); /* will also flush the output */
bb_putchar('\n'); /* will also flush the output */
}
#define WARN "warning: "
@ -300,7 +300,7 @@ static int status(const char *unused)
printf("; ");
svstatus_print("log");
}
puts(""); /* will also flush the output */
bb_putchar('\n'); /* will also flush the output */
return r;
}
@ -372,7 +372,7 @@ static int check(const char *a)
}
printf(OK);
svstatus_print(*service);
puts(""); /* will also flush the output */
bb_putchar('\n'); /* will also flush the output */
return 1;
}
@ -571,7 +571,7 @@ int sv_main(int argc, char **argv)
svstatus_print(*service);
++rc;
}
puts(""); /* will also flush the output */
bb_putchar('\n'); /* will also flush the output */
if (kll)
control("k");
nullify_service:

View File

@ -53,7 +53,7 @@ int getsebool_main(int argc, char **argv)
printf("%s --> %s", names[i], (active ? "on" : "off"));
if (pending != active)
printf(" pending: %s", (pending ? "on" : "off"));
putchar('\n');
bb_putchar('\n');
}
if (ENABLE_FEATURE_CLEAN_UP) {

View File

@ -284,8 +284,8 @@ static int restore(const char *file)
if (count % 0x400 == 0) { /* every 1024 times */
count = (count % (80*0x400));
if (count == 0)
fputc('\n', stdout);
fputc('*', stdout);
bb_putchar('\n');
bb_putchar('*');
fflush(stdout);
}
}

View File

@ -2004,7 +2004,7 @@ static int run_list_real(struct pipe *pi)
insert_bg_job(pi);
} else {
/* ctrl-C. We just stop doing whatever we were doing */
putchar('\n');
bb_putchar('\n');
}
rcode = 0;
goto ret;

View File

@ -319,7 +319,7 @@ static int builtin_help(struct child_prog ATTRIBUTE_UNUSED *dummy)
continue;
printf("%s\t%s\n", x->cmd, x->descr);
}
putchar('\n');
bb_putchar('\n');
return EXIT_SUCCESS;
}
@ -677,7 +677,7 @@ static int get_command_bufsiz(FILE * source, char *command)
if (!fgets(command, BUFSIZ - 2, source)) {
if (source == stdin)
puts("");
bb_putchar('\n');
return 1;
}

View File

@ -1137,7 +1137,7 @@ static void nameval(struct var *vp, const char *val, const char *name)
if (vp->status & RONLY) {
xp = vp->name;
while (*xp && *xp != '=')
putc(*xp++, stderr);
fputc(*xp++, stderr);
err(" is read-only");
return;
}
@ -3181,7 +3181,7 @@ static int dohelp(struct op *t)
while (x->name) {
col += printf("%c%s", ((col == 0) ? '\t' : ' '), x->name);
if (col > 60) {
puts("");
bb_putchar('\n');
col = 0;
}
x++;
@ -3193,7 +3193,7 @@ static int dohelp(struct op *t)
while (applet->name) {
col += printf("%c%s", ((col == 0) ? '\t' : ' '), applet->name);
if (col > 60) {
puts("");
bb_putchar('\n');
col = 0;
}
applet++;
@ -3274,8 +3274,8 @@ static int doumask(struct op *t)
i = umask(0);
umask(i);
for (n = 3 * 4; (n -= 3) >= 0;)
putc('0' + ((i >> n) & 07), stderr);
putc('\n', stderr);
fputc('0' + ((i >> n) & 07), stderr);
fputc('\n', stderr);
} else {
/* huh??? '8','9' are not allowed! */
for (n = 0; *cp >= '0' && *cp <= '9'; cp++)

View File

@ -38,12 +38,12 @@ int dmesg_main(int argc, char **argv)
for (in = 0; in<len;) {
if (last == '\n' && buf[in] == '<') in += 3;
else putchar(last = buf[in++]);
else bb_putchar(last = buf[in++]);
}
if (last != '\n') putchar('\n');
if (last != '\n') bb_putchar('\n');
} else {
write(1,buf,len);
if (len && buf[len-1]!='\n') putchar('\n');
if (len && buf[len-1]!='\n') bb_putchar('\n');
}
if (ENABLE_FEATURE_CLEAN_UP) free(buf);

View File

@ -892,7 +892,7 @@ list_types(const char *const *sys)
next = ++done;
}
} while (done < last[0]);
putchar('\n');
bb_putchar('\n');
}
#endif /* FEATURE_FDISK_WRITABLE */
@ -2473,13 +2473,13 @@ print_buffer(char *pbuffer)
printf("0x%03X:", i);
printf(" %02X", (unsigned char) pbuffer[i]);
if (l == MAX_PER_LINE - 1) {
puts("");
bb_putchar('\n');
l = -1;
}
}
if (l > 0)
puts("");
puts("");
bb_putchar('\n');
bb_putchar('\n');
}
static void
@ -2527,7 +2527,7 @@ xselect(void)
char c;
while (1) {
putchar('\n');
bb_putchar('\n');
c = tolower(read_nonempty("Expert command (m for help): "));
switch (c) {
case 'a':
@ -2588,7 +2588,7 @@ xselect(void)
break;
case 'q':
close(fd);
puts("");
bb_putchar('\n');
exit(0);
case 'r':
return;
@ -2867,7 +2867,7 @@ int fdisk_main(int argc, char **argv)
while (1) {
int c;
putchar('\n');
bb_putchar('\n');
c = tolower(read_nonempty("Command (m for help): "));
switch (c) {
case 'a':
@ -2947,7 +2947,7 @@ int fdisk_main(int argc, char **argv)
break;
case 'q':
close(fd);
puts("");
bb_putchar('\n');
return 0;
case 's':
#if ENABLE_FEATURE_SUN_LABEL

View File

@ -394,7 +394,7 @@ bsd_select(void)
#endif
while (1) {
putchar('\n');
bb_putchar('\n');
switch (tolower(read_nonempty("BSD disklabel command (m for help): "))) {
case 'd':
xbsd_delete_part();
@ -521,7 +521,7 @@ xbsd_print_disklabel(int show_all)
printf(" ecc");
if (lp->d_flags & BSD_D_BADSECT)
printf(" badsect");
puts("");
bb_putchar('\n');
/* On various machines the fields of *lp are short/int/long */
/* In order to avoid problems, we cast them all to long. */
printf("bytes/sector: %ld\n", (long) lp->d_secsize);
@ -588,7 +588,7 @@ xbsd_print_disklabel(int show_all)
printf("%22.22s", "");
break;
}
puts("");
bb_putchar('\n');
}
}
}

View File

@ -307,12 +307,12 @@ static int ask(const char *string, int def)
int c;
if (!repair) {
puts("");
bb_putchar('\n');
errors_uncorrected = 1;
return 0;
}
if (automatic) {
puts("");
bb_putchar('\n');
if (!def)
errors_uncorrected = 1;
return def;

View File

@ -195,7 +195,7 @@ static int generate_output(char **argv, int argc, const char *optstr, const stru
printf(" --");
while (optind < argc)
printf(" %s", normalize(argv[optind++]));
puts("");
bb_putchar('\n');
}
return exit_code;
}

View File

@ -555,7 +555,7 @@ static void print_sem(int semid)
}
printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
}
puts("");
bb_putchar('\n');
}
int ipcs_main(int argc, char **argv);
@ -603,19 +603,19 @@ int ipcs_main(int argc, char **argv)
if (!(flags & (flag_shm | flag_msg | flag_sem)))
flags |= flag_msg | flag_shm | flag_sem;
puts("");
bb_putchar('\n');
if (flags & flag_shm) {
do_shm();
puts("");
bb_putchar('\n');
}
if (flags & flag_sem) {
do_sem();
puts("");
bb_putchar('\n');
}
if (flags & flag_msg) {
do_msg();
puts("");
bb_putchar('\n');
}
fflush_stdout_and_exit(0);
}

View File

@ -40,7 +40,7 @@ struct globals {
static void gotsig(int sig)
{
putchar('\n');
bb_putchar('\n');
setTermSettings(cin_fileno, &initial_settings);
exit(EXIT_FAILURE);
}