Eliminate calls of the form "fprintf(stdout,". Thanks for the idea to

Vladimir N. Oleynik.
This commit is contained in:
Matt Kraai 2001-01-18 02:57:08 +00:00
parent c9acf8c766
commit 12f417edbd
20 changed files with 102 additions and 108 deletions

View File

@ -147,7 +147,7 @@ static void cmdedit_reset_term(void)
static void clean_up_and_die(int sig) static void clean_up_and_die(int sig)
{ {
cmdedit_reset_term(); cmdedit_reset_term();
fprintf(stdout, "\n"); printf("\n");
if (sig!=SIGINT) if (sig!=SIGINT)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -42,7 +42,7 @@ static Display *print;
static void print_normal(long size, char *filename) static void print_normal(long size, char *filename)
{ {
fprintf(stdout, "%ld\t%s\n", size, filename); printf("%ld\t%s\n", size, filename);
} }
static void print_summary(long size, char *filename) static void print_summary(long size, char *filename)
@ -165,7 +165,7 @@ int du_main(int argc, char **argv)
return status; return status;
} }
/* $Id: du.c,v 1.32 2000/12/12 23:17:26 andersen Exp $ */ /* $Id: du.c,v 1.33 2001/01/18 02:57:08 kraai Exp $ */
/* /*
Local Variables: Local Variables:
c-file-style: "linux" c-file-style: "linux"

View File

@ -76,7 +76,7 @@ int head_main(int argc, char **argv)
} }
if (fp) { if (fp) {
if (need_headers) { if (need_headers) {
fprintf(stdout, "==> %s <==\n", argv[optind]); printf("==> %s <==\n", argv[optind]);
} }
head(len, fp); head(len, fp);
if (errno) { if (errno) {
@ -85,7 +85,7 @@ int head_main(int argc, char **argv)
errno = 0; errno = 0;
} }
if (optind < argc - 1) if (optind < argc - 1)
fprintf(stdout, "\n"); putchar('\n');
if (fp != stdin) if (fp != stdin)
fclose(fp); fclose(fp);
} }

View File

@ -202,7 +202,7 @@ static int my_stat(struct dnode *cur)
static void newline(void) static void newline(void)
{ {
if (column > 0) { if (column > 0) {
fprintf(stdout, "\n"); putchar('\n');
column = 0; column = 0;
} }
} }
@ -229,7 +229,7 @@ static void nexttabstop( void )
n= nexttab - column; n= nexttab - column;
if (n < 1) n= 1; if (n < 1) n= 1;
while (n--) { while (n--) {
fprintf(stdout, " "); putchar(' ');
column++; column++;
} }
} }
@ -468,7 +468,7 @@ void showdirs(struct dnode **dn, int ndirs)
for (i=0; i<ndirs; i++) { for (i=0; i<ndirs; i++) {
if (disp_opts & (DISP_DIRNAME | DISP_RECURSIVE)) { if (disp_opts & (DISP_DIRNAME | DISP_RECURSIVE)) {
fprintf(stdout, "\n%s:\n", dn[i]->fullname); printf("\n%s:\n", dn[i]->fullname);
} }
subdnp= list_dir(dn[i]->fullname); subdnp= list_dir(dn[i]->fullname);
nfiles= countfiles(subdnp); nfiles= countfiles(subdnp);
@ -579,53 +579,53 @@ int list_single(struct dnode *dn)
for (i=0; i<=31; i++) { for (i=0; i<=31; i++) {
switch (list_fmt & (1<<i)) { switch (list_fmt & (1<<i)) {
case LIST_INO: case LIST_INO:
fprintf(stdout, "%7ld ", dn->dstat.st_ino); printf("%7ld ", dn->dstat.st_ino);
column += 8; column += 8;
break; break;
case LIST_BLOCKS: case LIST_BLOCKS:
#if _FILE_OFFSET_BITS == 64 #if _FILE_OFFSET_BITS == 64
fprintf(stdout, "%4lld ", dn->dstat.st_blocks>>1); printf("%4lld ", dn->dstat.st_blocks>>1);
#else #else
fprintf(stdout, "%4ld ", dn->dstat.st_blocks>>1); printf("%4ld ", dn->dstat.st_blocks>>1);
#endif #endif
column += 5; column += 5;
break; break;
case LIST_MODEBITS: case LIST_MODEBITS:
fprintf(stdout, "%10s", (char *)mode_string(dn->dstat.st_mode)); printf("%10s", (char *)mode_string(dn->dstat.st_mode));
column += 10; column += 10;
break; break;
case LIST_NLINKS: case LIST_NLINKS:
fprintf(stdout, "%4d ", dn->dstat.st_nlink); printf("%4d ", dn->dstat.st_nlink);
column += 10; column += 10;
break; break;
case LIST_ID_NAME: case LIST_ID_NAME:
#ifdef BB_FEATURE_LS_USERNAME #ifdef BB_FEATURE_LS_USERNAME
my_getpwuid(scratch, dn->dstat.st_uid); my_getpwuid(scratch, dn->dstat.st_uid);
if (*scratch) if (*scratch)
fprintf(stdout, "%-8.8s ", scratch); printf("%-8.8s ", scratch);
else else
fprintf(stdout, "%-8d ", dn->dstat.st_uid); printf("%-8d ", dn->dstat.st_uid);
my_getgrgid(scratch, dn->dstat.st_gid); my_getgrgid(scratch, dn->dstat.st_gid);
if (*scratch) if (*scratch)
fprintf(stdout, "%-8.8s", scratch); printf("%-8.8s", scratch);
else else
fprintf(stdout, "%-8d", dn->dstat.st_gid); printf("%-8d", dn->dstat.st_gid);
column += 17; column += 17;
break; break;
#endif #endif
case LIST_ID_NUMERIC: case LIST_ID_NUMERIC:
fprintf(stdout, "%-8d %-8d", dn->dstat.st_uid, dn->dstat.st_gid); printf("%-8d %-8d", dn->dstat.st_uid, dn->dstat.st_gid);
column += 17; column += 17;
break; break;
case LIST_SIZE: case LIST_SIZE:
case LIST_DEV: case LIST_DEV:
if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
fprintf(stdout, "%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
} else { } else {
#if _FILE_OFFSET_BITS == 64 #if _FILE_OFFSET_BITS == 64
fprintf(stdout, "%9lld ", dn->dstat.st_size); printf("%9lld ", dn->dstat.st_size);
#else #else
fprintf(stdout, "%9ld ", dn->dstat.st_size); printf("%9ld ", dn->dstat.st_size);
#endif #endif
} }
column += 10; column += 10;
@ -634,23 +634,23 @@ int list_single(struct dnode *dn)
case LIST_FULLTIME: case LIST_FULLTIME:
case LIST_DATE_TIME: case LIST_DATE_TIME:
if (list_fmt & LIST_FULLTIME) { if (list_fmt & LIST_FULLTIME) {
fprintf(stdout, "%24.24s ", filetime); printf("%24.24s ", filetime);
column += 25; column += 25;
break; break;
} }
age = time(NULL) - ttime; age = time(NULL) - ttime;
fprintf(stdout, "%6.6s ", filetime+4); printf("%6.6s ", filetime+4);
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
/* hh:mm if less than 6 months old */ /* hh:mm if less than 6 months old */
fprintf(stdout, "%5.5s ", filetime+11); printf("%5.5s ", filetime+11);
} else { } else {
fprintf(stdout, " %4.4s ", filetime+20); printf(" %4.4s ", filetime+20);
} }
column += 13; column += 13;
break; break;
#endif #endif
case LIST_FILENAME: case LIST_FILENAME:
fprintf(stdout, "%s", dn->name); printf("%s", dn->name);
column += strlen(dn->name); column += strlen(dn->name);
break; break;
case LIST_SYMLINK: case LIST_SYMLINK:
@ -658,7 +658,7 @@ int list_single(struct dnode *dn)
len= readlink(dn->fullname, scratch, (sizeof scratch)-1); len= readlink(dn->fullname, scratch, (sizeof scratch)-1);
if (len > 0) { if (len > 0) {
scratch[len]= '\0'; scratch[len]= '\0';
fprintf(stdout, " -> %s", scratch); printf(" -> %s", scratch);
#ifdef BB_FEATURE_LS_FILETYPES #ifdef BB_FEATURE_LS_FILETYPES
if (!stat(dn->fullname, &info)) { if (!stat(dn->fullname, &info)) {
append = append_char(info.st_mode); append = append_char(info.st_mode);
@ -671,7 +671,7 @@ int list_single(struct dnode *dn)
#ifdef BB_FEATURE_LS_FILETYPES #ifdef BB_FEATURE_LS_FILETYPES
case LIST_FILETYPE: case LIST_FILETYPE:
if (append != '\0') { if (append != '\0') {
fprintf(stdout, "%1c", append); printf("%1c", append);
column++; column++;
} }
break; break;

4
du.c
View File

@ -42,7 +42,7 @@ static Display *print;
static void print_normal(long size, char *filename) static void print_normal(long size, char *filename)
{ {
fprintf(stdout, "%ld\t%s\n", size, filename); printf("%ld\t%s\n", size, filename);
} }
static void print_summary(long size, char *filename) static void print_summary(long size, char *filename)
@ -165,7 +165,7 @@ int du_main(int argc, char **argv)
return status; return status;
} }
/* $Id: du.c,v 1.32 2000/12/12 23:17:26 andersen Exp $ */ /* $Id: du.c,v 1.33 2001/01/18 02:57:08 kraai Exp $ */
/* /*
Local Variables: Local Variables:
c-file-style: "linux" c-file-style: "linux"

4
find.c
View File

@ -35,7 +35,7 @@ static int dereferenceFlag = FALSE;
static int fileAction(const char *fileName, struct stat *statbuf, void* junk) static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{ {
if (pattern == NULL) if (pattern == NULL)
fprintf(stdout, "%s\n", fileName); puts(fileName);
else { else {
char *tmp = strrchr(fileName, '/'); char *tmp = strrchr(fileName, '/');
@ -44,7 +44,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
else else
tmp++; tmp++;
if (check_wildcard_match(tmp, pattern) == TRUE) if (check_wildcard_match(tmp, pattern) == TRUE)
fprintf(stdout, "%s\n", fileName); puts(fileName);
} }
return (TRUE); return (TRUE);
} }

View File

@ -35,7 +35,7 @@ static int dereferenceFlag = FALSE;
static int fileAction(const char *fileName, struct stat *statbuf, void* junk) static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{ {
if (pattern == NULL) if (pattern == NULL)
fprintf(stdout, "%s\n", fileName); puts(fileName);
else { else {
char *tmp = strrchr(fileName, '/'); char *tmp = strrchr(fileName, '/');
@ -44,7 +44,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
else else
tmp++; tmp++;
if (check_wildcard_match(tmp, pattern) == TRUE) if (check_wildcard_match(tmp, pattern) == TRUE)
fprintf(stdout, "%s\n", fileName); puts(fileName);
} }
return (TRUE); return (TRUE);
} }

4
head.c
View File

@ -76,7 +76,7 @@ int head_main(int argc, char **argv)
} }
if (fp) { if (fp) {
if (need_headers) { if (need_headers) {
fprintf(stdout, "==> %s <==\n", argv[optind]); printf("==> %s <==\n", argv[optind]);
} }
head(len, fp); head(len, fp);
if (errno) { if (errno) {
@ -85,7 +85,7 @@ int head_main(int argc, char **argv)
errno = 0; errno = 0;
} }
if (optind < argc - 1) if (optind < argc - 1)
fprintf(stdout, "\n"); putchar('\n');
if (fp != stdin) if (fp != stdin)
fclose(fp); fclose(fp);
} }

46
ls.c
View File

@ -202,7 +202,7 @@ static int my_stat(struct dnode *cur)
static void newline(void) static void newline(void)
{ {
if (column > 0) { if (column > 0) {
fprintf(stdout, "\n"); putchar('\n');
column = 0; column = 0;
} }
} }
@ -229,7 +229,7 @@ static void nexttabstop( void )
n= nexttab - column; n= nexttab - column;
if (n < 1) n= 1; if (n < 1) n= 1;
while (n--) { while (n--) {
fprintf(stdout, " "); putchar(' ');
column++; column++;
} }
} }
@ -468,7 +468,7 @@ void showdirs(struct dnode **dn, int ndirs)
for (i=0; i<ndirs; i++) { for (i=0; i<ndirs; i++) {
if (disp_opts & (DISP_DIRNAME | DISP_RECURSIVE)) { if (disp_opts & (DISP_DIRNAME | DISP_RECURSIVE)) {
fprintf(stdout, "\n%s:\n", dn[i]->fullname); printf("\n%s:\n", dn[i]->fullname);
} }
subdnp= list_dir(dn[i]->fullname); subdnp= list_dir(dn[i]->fullname);
nfiles= countfiles(subdnp); nfiles= countfiles(subdnp);
@ -579,53 +579,53 @@ int list_single(struct dnode *dn)
for (i=0; i<=31; i++) { for (i=0; i<=31; i++) {
switch (list_fmt & (1<<i)) { switch (list_fmt & (1<<i)) {
case LIST_INO: case LIST_INO:
fprintf(stdout, "%7ld ", dn->dstat.st_ino); printf("%7ld ", dn->dstat.st_ino);
column += 8; column += 8;
break; break;
case LIST_BLOCKS: case LIST_BLOCKS:
#if _FILE_OFFSET_BITS == 64 #if _FILE_OFFSET_BITS == 64
fprintf(stdout, "%4lld ", dn->dstat.st_blocks>>1); printf("%4lld ", dn->dstat.st_blocks>>1);
#else #else
fprintf(stdout, "%4ld ", dn->dstat.st_blocks>>1); printf("%4ld ", dn->dstat.st_blocks>>1);
#endif #endif
column += 5; column += 5;
break; break;
case LIST_MODEBITS: case LIST_MODEBITS:
fprintf(stdout, "%10s", (char *)mode_string(dn->dstat.st_mode)); printf("%10s", (char *)mode_string(dn->dstat.st_mode));
column += 10; column += 10;
break; break;
case LIST_NLINKS: case LIST_NLINKS:
fprintf(stdout, "%4d ", dn->dstat.st_nlink); printf("%4d ", dn->dstat.st_nlink);
column += 10; column += 10;
break; break;
case LIST_ID_NAME: case LIST_ID_NAME:
#ifdef BB_FEATURE_LS_USERNAME #ifdef BB_FEATURE_LS_USERNAME
my_getpwuid(scratch, dn->dstat.st_uid); my_getpwuid(scratch, dn->dstat.st_uid);
if (*scratch) if (*scratch)
fprintf(stdout, "%-8.8s ", scratch); printf("%-8.8s ", scratch);
else else
fprintf(stdout, "%-8d ", dn->dstat.st_uid); printf("%-8d ", dn->dstat.st_uid);
my_getgrgid(scratch, dn->dstat.st_gid); my_getgrgid(scratch, dn->dstat.st_gid);
if (*scratch) if (*scratch)
fprintf(stdout, "%-8.8s", scratch); printf("%-8.8s", scratch);
else else
fprintf(stdout, "%-8d", dn->dstat.st_gid); printf("%-8d", dn->dstat.st_gid);
column += 17; column += 17;
break; break;
#endif #endif
case LIST_ID_NUMERIC: case LIST_ID_NUMERIC:
fprintf(stdout, "%-8d %-8d", dn->dstat.st_uid, dn->dstat.st_gid); printf("%-8d %-8d", dn->dstat.st_uid, dn->dstat.st_gid);
column += 17; column += 17;
break; break;
case LIST_SIZE: case LIST_SIZE:
case LIST_DEV: case LIST_DEV:
if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
fprintf(stdout, "%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
} else { } else {
#if _FILE_OFFSET_BITS == 64 #if _FILE_OFFSET_BITS == 64
fprintf(stdout, "%9lld ", dn->dstat.st_size); printf("%9lld ", dn->dstat.st_size);
#else #else
fprintf(stdout, "%9ld ", dn->dstat.st_size); printf("%9ld ", dn->dstat.st_size);
#endif #endif
} }
column += 10; column += 10;
@ -634,23 +634,23 @@ int list_single(struct dnode *dn)
case LIST_FULLTIME: case LIST_FULLTIME:
case LIST_DATE_TIME: case LIST_DATE_TIME:
if (list_fmt & LIST_FULLTIME) { if (list_fmt & LIST_FULLTIME) {
fprintf(stdout, "%24.24s ", filetime); printf("%24.24s ", filetime);
column += 25; column += 25;
break; break;
} }
age = time(NULL) - ttime; age = time(NULL) - ttime;
fprintf(stdout, "%6.6s ", filetime+4); printf("%6.6s ", filetime+4);
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
/* hh:mm if less than 6 months old */ /* hh:mm if less than 6 months old */
fprintf(stdout, "%5.5s ", filetime+11); printf("%5.5s ", filetime+11);
} else { } else {
fprintf(stdout, " %4.4s ", filetime+20); printf(" %4.4s ", filetime+20);
} }
column += 13; column += 13;
break; break;
#endif #endif
case LIST_FILENAME: case LIST_FILENAME:
fprintf(stdout, "%s", dn->name); printf("%s", dn->name);
column += strlen(dn->name); column += strlen(dn->name);
break; break;
case LIST_SYMLINK: case LIST_SYMLINK:
@ -658,7 +658,7 @@ int list_single(struct dnode *dn)
len= readlink(dn->fullname, scratch, (sizeof scratch)-1); len= readlink(dn->fullname, scratch, (sizeof scratch)-1);
if (len > 0) { if (len > 0) {
scratch[len]= '\0'; scratch[len]= '\0';
fprintf(stdout, " -> %s", scratch); printf(" -> %s", scratch);
#ifdef BB_FEATURE_LS_FILETYPES #ifdef BB_FEATURE_LS_FILETYPES
if (!stat(dn->fullname, &info)) { if (!stat(dn->fullname, &info)) {
append = append_char(info.st_mode); append = append_char(info.st_mode);
@ -671,7 +671,7 @@ int list_single(struct dnode *dn)
#ifdef BB_FEATURE_LS_FILETYPES #ifdef BB_FEATURE_LS_FILETYPES
case LIST_FILETYPE: case LIST_FILETYPE:
if (append != '\0') { if (append != '\0') {
fprintf(stdout, "%1c", append); printf("%1c", append);
column++; column++;
} }
break; break;

12
more.c
View File

@ -54,8 +54,8 @@ static struct termios initial_settings, new_settings;
static void gotsig(int sig) static void gotsig(int sig)
{ {
setTermSettings(fileno(cin), &initial_settings); setTermSettings(fileno(cin), &initial_settings);
fprintf(stdout, "\n"); putchar('\n');
exit(TRUE); exit(EXIT_FAILURE);
} }
#endif /* BB_FEATURE_USE_TERMIOS */ #endif /* BB_FEATURE_USE_TERMIOS */
@ -117,19 +117,19 @@ extern int more_main(int argc, char **argv)
please_display_more_prompt = 0; please_display_more_prompt = 0;
lines = 0; lines = 0;
len = fprintf(stdout, "--More-- "); len = printf("--More-- ");
if (file != stdin) { if (file != stdin) {
#if _FILE_OFFSET_BITS == 64 #if _FILE_OFFSET_BITS == 64
len += fprintf(stdout, "(%d%% of %lld bytes)", len += printf("(%d%% of %lld bytes)",
#else #else
len += fprintf(stdout, "(%d%% of %ld bytes)", len += printf("(%d%% of %ld bytes)",
#endif #endif
(int) (100 * (int) (100 *
((double) ftell(file) / ((double) ftell(file) /
(double) st.st_size)), (double) st.st_size)),
st.st_size); st.st_size);
} }
len += fprintf(stdout, "%s", len += printf("%s",
#ifdef BB_FEATURE_USE_TERMIOS #ifdef BB_FEATURE_USE_TERMIOS
"" ""
#else #else

View File

@ -332,7 +332,7 @@ static void setConMode()
{ {
if (G.charmode == CHM_TRY) { if (G.charmode == CHM_TRY) {
G.charmode = CHM_ON; G.charmode = CHM_ON;
fprintf(stdout, "\r\nEntering character mode%s'^]'.\r\n", escapecharis); printf("\r\nEntering character mode%s'^]'.\r\n", escapecharis);
rawmode(); rawmode();
} }
} }
@ -340,7 +340,7 @@ static void setConMode()
{ {
if (G.charmode != CHM_OFF) { if (G.charmode != CHM_OFF) {
G.charmode = CHM_OFF; G.charmode = CHM_OFF;
fprintf(stdout, "\r\nEntering line mode%s'^C'.\r\n", escapecharis); printf("\r\nEntering line mode%s'^C'.\r\n", escapecharis);
cookmode(); cookmode();
} }
} }

View File

@ -143,8 +143,7 @@ extern int ps_main(int argc, char **argv)
terminal_width = win.ws_col - 1; terminal_width = win.ws_col - 1;
#endif #endif
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", printf("%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", "State", "Command");
"State", "Command");
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
if (!isdigit(*entry->d_name)) if (!isdigit(*entry->d_name))
continue; continue;
@ -166,8 +165,7 @@ extern int ps_main(int argc, char **argv)
if (file == NULL) if (file == NULL)
continue; continue;
i = 0; i = 0;
len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName, len = printf("%5d %-8s %-8s %c ", p.pid, uidName, groupName, p.state);
p.state);
while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) { while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
i++; i++;
if (c == '\0') if (c == '\0')
@ -176,8 +174,8 @@ extern int ps_main(int argc, char **argv)
} }
fclose(file); fclose(file);
if (i == 0) if (i == 0)
fprintf(stdout, "[%s]", p.cmd); printf("[%s]", p.cmd);
fprintf(stdout, "\n"); putchar('\n');
} }
closedir(dir); closedir(dir);
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -240,8 +238,7 @@ extern int ps_main(int argc, char **argv)
#endif #endif
/* Print up a ps listing */ /* Print up a ps listing */
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", printf("%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", "State", "Command");
"State", "Command");
for (i=1; i<pid_array[0] ; i++) { for (i=1; i<pid_array[0] ; i++) {
info.pid = pid_array[i]; info.pid = pid_array[i];
@ -257,7 +254,7 @@ extern int ps_main(int argc, char **argv)
if (*groupName == '\0') if (*groupName == '\0')
sprintf(groupName, "%ld", info.egid); sprintf(groupName, "%ld", info.egid);
len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state); len = printf("%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);
if (strlen(info.command_line) > 1) { if (strlen(info.command_line) > 1) {
for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) { for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
@ -266,9 +263,9 @@ extern int ps_main(int argc, char **argv)
} }
} }
*(info.command_line+j) = '\0'; *(info.command_line+j) = '\0';
fprintf(stdout, "%s\n", info.command_line); puts(info.command_line);
} else { } else {
fprintf(stdout, "[%s]\n", info.name); printf("[%s]\n", info.name);
} }
} }

View File

@ -51,19 +51,19 @@ extern int uptime_main(int argc, char **argv)
sysinfo(&info); sysinfo(&info);
fprintf(stdout, " %2d:%02d%s up ", printf(" %2d:%02d%s up ",
current_time->tm_hour%12 ? current_time->tm_hour%12 : 12, current_time->tm_hour%12 ? current_time->tm_hour%12 : 12,
current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am"); current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am");
updays = (int) info.uptime / (60*60*24); updays = (int) info.uptime / (60*60*24);
if (updays) if (updays)
fprintf(stdout, "%d day%s, ", updays, (updays != 1) ? "s" : ""); printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
upminutes = (int) info.uptime / 60; upminutes = (int) info.uptime / 60;
uphours = (upminutes / 60) % 24; uphours = (upminutes / 60) % 24;
upminutes %= 60; upminutes %= 60;
if(uphours) if(uphours)
fprintf(stdout, "%2d:%02d, ", uphours, upminutes); printf("%2d:%02d, ", uphours, upminutes);
else else
fprintf(stdout, "%d min, ", upminutes); printf("%d min, ", upminutes);
printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),

19
ps.c
View File

@ -143,8 +143,7 @@ extern int ps_main(int argc, char **argv)
terminal_width = win.ws_col - 1; terminal_width = win.ws_col - 1;
#endif #endif
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", printf("%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", "State", "Command");
"State", "Command");
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
if (!isdigit(*entry->d_name)) if (!isdigit(*entry->d_name))
continue; continue;
@ -166,8 +165,7 @@ extern int ps_main(int argc, char **argv)
if (file == NULL) if (file == NULL)
continue; continue;
i = 0; i = 0;
len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName, len = printf("%5d %-8s %-8s %c ", p.pid, uidName, groupName, p.state);
p.state);
while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) { while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
i++; i++;
if (c == '\0') if (c == '\0')
@ -176,8 +174,8 @@ extern int ps_main(int argc, char **argv)
} }
fclose(file); fclose(file);
if (i == 0) if (i == 0)
fprintf(stdout, "[%s]", p.cmd); printf("[%s]", p.cmd);
fprintf(stdout, "\n"); putchar('\n');
} }
closedir(dir); closedir(dir);
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -240,8 +238,7 @@ extern int ps_main(int argc, char **argv)
#endif #endif
/* Print up a ps listing */ /* Print up a ps listing */
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", printf("%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", "State", "Command");
"State", "Command");
for (i=1; i<pid_array[0] ; i++) { for (i=1; i<pid_array[0] ; i++) {
info.pid = pid_array[i]; info.pid = pid_array[i];
@ -257,7 +254,7 @@ extern int ps_main(int argc, char **argv)
if (*groupName == '\0') if (*groupName == '\0')
sprintf(groupName, "%ld", info.egid); sprintf(groupName, "%ld", info.egid);
len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state); len = printf("%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);
if (strlen(info.command_line) > 1) { if (strlen(info.command_line) > 1) {
for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) { for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
@ -266,9 +263,9 @@ extern int ps_main(int argc, char **argv)
} }
} }
*(info.command_line+j) = '\0'; *(info.command_line+j) = '\0';
fprintf(stdout, "%s\n", info.command_line); puts(info.command_line);
} else { } else {
fprintf(stdout, "[%s]\n", info.name); printf("[%s]\n", info.name);
} }
} }

View File

@ -126,7 +126,7 @@ int rdate_main(int argc, char **argv)
perror_msg_and_die("Could not set time of day"); perror_msg_and_die("Could not set time of day");
} }
if (printdate) { if (printdate) {
fprintf(stdout, "%s", ctime(&time)); printf("%s", ctime(&time));
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -147,7 +147,7 @@ static void cmdedit_reset_term(void)
static void clean_up_and_die(int sig) static void clean_up_and_die(int sig)
{ {
cmdedit_reset_term(); cmdedit_reset_term();
fprintf(stdout, "\n"); printf("\n");
if (sig!=SIGINT) if (sig!=SIGINT)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -332,7 +332,7 @@ static void setConMode()
{ {
if (G.charmode == CHM_TRY) { if (G.charmode == CHM_TRY) {
G.charmode = CHM_ON; G.charmode = CHM_ON;
fprintf(stdout, "\r\nEntering character mode%s'^]'.\r\n", escapecharis); printf("\r\nEntering character mode%s'^]'.\r\n", escapecharis);
rawmode(); rawmode();
} }
} }
@ -340,7 +340,7 @@ static void setConMode()
{ {
if (G.charmode != CHM_OFF) { if (G.charmode != CHM_OFF) {
G.charmode = CHM_OFF; G.charmode = CHM_OFF;
fprintf(stdout, "\r\nEntering line mode%s'^C'.\r\n", escapecharis); printf("\r\nEntering line mode%s'^C'.\r\n", escapecharis);
cookmode(); cookmode();
} }
} }

View File

@ -51,19 +51,19 @@ extern int uptime_main(int argc, char **argv)
sysinfo(&info); sysinfo(&info);
fprintf(stdout, " %2d:%02d%s up ", printf(" %2d:%02d%s up ",
current_time->tm_hour%12 ? current_time->tm_hour%12 : 12, current_time->tm_hour%12 ? current_time->tm_hour%12 : 12,
current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am"); current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am");
updays = (int) info.uptime / (60*60*24); updays = (int) info.uptime / (60*60*24);
if (updays) if (updays)
fprintf(stdout, "%d day%s, ", updays, (updays != 1) ? "s" : ""); printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
upminutes = (int) info.uptime / 60; upminutes = (int) info.uptime / 60;
uphours = (upminutes / 60) % 24; uphours = (upminutes / 60) % 24;
upminutes %= 60; upminutes %= 60;
if(uphours) if(uphours)
fprintf(stdout, "%2d:%02d, ", uphours, upminutes); printf("%2d:%02d, ", uphours, upminutes);
else else
fprintf(stdout, "%d min, ", upminutes); printf("%d min, ", upminutes);
printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),

View File

@ -54,8 +54,8 @@ static struct termios initial_settings, new_settings;
static void gotsig(int sig) static void gotsig(int sig)
{ {
setTermSettings(fileno(cin), &initial_settings); setTermSettings(fileno(cin), &initial_settings);
fprintf(stdout, "\n"); putchar('\n');
exit(TRUE); exit(EXIT_FAILURE);
} }
#endif /* BB_FEATURE_USE_TERMIOS */ #endif /* BB_FEATURE_USE_TERMIOS */
@ -117,19 +117,19 @@ extern int more_main(int argc, char **argv)
please_display_more_prompt = 0; please_display_more_prompt = 0;
lines = 0; lines = 0;
len = fprintf(stdout, "--More-- "); len = printf("--More-- ");
if (file != stdin) { if (file != stdin) {
#if _FILE_OFFSET_BITS == 64 #if _FILE_OFFSET_BITS == 64
len += fprintf(stdout, "(%d%% of %lld bytes)", len += printf("(%d%% of %lld bytes)",
#else #else
len += fprintf(stdout, "(%d%% of %ld bytes)", len += printf("(%d%% of %ld bytes)",
#endif #endif
(int) (100 * (int) (100 *
((double) ftell(file) / ((double) ftell(file) /
(double) st.st_size)), (double) st.st_size)),
st.st_size); st.st_size);
} }
len += fprintf(stdout, "%s", len += printf("%s",
#ifdef BB_FEATURE_USE_TERMIOS #ifdef BB_FEATURE_USE_TERMIOS
"" ""
#else #else

View File

@ -126,7 +126,7 @@ int rdate_main(int argc, char **argv)
perror_msg_and_die("Could not set time of day"); perror_msg_and_die("Could not set time of day");
} }
if (printdate) { if (printdate) {
fprintf(stdout, "%s", ctime(&time)); printf("%s", ctime(&time));
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;