aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-26 23:21:47 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-26 23:21:47 +0000
commitf0ed376eda5d5c25d270e5100a881fb2d801bee6 (patch)
tree79166b700c497fbe798b6031e5bbff97e0933573 /miscutils
parent670a6626cabc1498f32b35f959591f8621d8447e (diff)
downloadbusybox-w32-f0ed376eda5d5c25d270e5100a881fb2d801bee6.tar.gz
busybox-w32-f0ed376eda5d5c25d270e5100a881fb2d801bee6.tar.bz2
busybox-w32-f0ed376eda5d5c25d270e5100a881fb2d801bee6.zip
remove bb_printf and the like
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/crond.c24
-rw-r--r--miscutils/devfsd.c8
-rw-r--r--miscutils/last.c2
-rw-r--r--miscutils/less.c39
-rw-r--r--miscutils/mountpoint.c73
-rw-r--r--miscutils/rx.c2
-rw-r--r--miscutils/strings.c2
7 files changed, 81 insertions, 69 deletions
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 4fc940b79..b18e27489 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -264,7 +264,7 @@ int crond_main(int ac, char **av)
264 } 264 }
265 } 265 }
266 } 266 }
267 bb_fflush_stdout_and_exit(EXIT_SUCCESS); /* not reached */ 267 return 0; /* not reached */
268} 268}
269 269
270static int ChangeUser(const char *user) 270static int ChangeUser(const char *user)
@@ -278,7 +278,7 @@ static int ChangeUser(const char *user)
278 pas = getpwnam(user); 278 pas = getpwnam(user);
279 if (pas == 0) { 279 if (pas == 0) {
280 crondlog("\011failed to get uid for %s", user); 280 crondlog("\011failed to get uid for %s", user);
281 return (-1); 281 return -1;
282 } 282 }
283 setenv("USER", pas->pw_name, 1); 283 setenv("USER", pas->pw_name, 1);
284 setenv("HOME", pas->pw_dir, 1); 284 setenv("HOME", pas->pw_dir, 1);
@@ -290,16 +290,16 @@ static int ChangeUser(const char *user)
290 err_msg = change_identity_e2str(pas); 290 err_msg = change_identity_e2str(pas);
291 if (err_msg) { 291 if (err_msg) {
292 crondlog("\011%s for user %s", err_msg, user); 292 crondlog("\011%s for user %s", err_msg, user);
293 return (-1); 293 return -1;
294 } 294 }
295 if (chdir(pas->pw_dir) < 0) { 295 if (chdir(pas->pw_dir) < 0) {
296 crondlog("\011chdir failed: %s: %m", pas->pw_dir); 296 crondlog("\011chdir failed: %s: %m", pas->pw_dir);
297 if (chdir(TMPDIR) < 0) { 297 if (chdir(TMPDIR) < 0) {
298 crondlog("\011chdir failed: %s: %m", TMPDIR); 298 crondlog("\011chdir failed: %s: %m", TMPDIR);
299 return (-1); 299 return -1;
300 } 300 }
301 } 301 }
302 return (pas->pw_uid); 302 return pas->pw_uid;
303} 303}
304 304
305static void startlogger(void) 305static void startlogger(void)
@@ -377,7 +377,7 @@ static char *ParseField(char *user, char *ary, int modvalue, int off,
377 int n2 = -1; 377 int n2 = -1;
378 378
379 if (base == NULL) { 379 if (base == NULL) {
380 return (NULL); 380 return NULL;
381 } 381 }
382 382
383 while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n') { 383 while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n') {
@@ -420,7 +420,7 @@ static char *ParseField(char *user, char *ary, int modvalue, int off,
420 420
421 if (skip == 0) { 421 if (skip == 0) {
422 crondlog("\111failed user %s parsing %s\n", user, base); 422 crondlog("\111failed user %s parsing %s\n", user, base);
423 return (NULL); 423 return NULL;
424 } 424 }
425 if (*ptr == '-' && n2 < 0) { 425 if (*ptr == '-' && n2 < 0) {
426 ++ptr; 426 ++ptr;
@@ -460,7 +460,7 @@ static char *ParseField(char *user, char *ary, int modvalue, int off,
460 460
461 if (failsafe == 0) { 461 if (failsafe == 0) {
462 crondlog("\111failed user %s parsing %s\n", user, base); 462 crondlog("\111failed user %s parsing %s\n", user, base);
463 return (NULL); 463 return NULL;
464 } 464 }
465 } 465 }
466 if (*ptr != ',') { 466 if (*ptr != ',') {
@@ -473,7 +473,7 @@ static char *ParseField(char *user, char *ary, int modvalue, int off,
473 473
474 if (*ptr != ' ' && *ptr != '\t' && *ptr != '\n') { 474 if (*ptr != ' ' && *ptr != '\t' && *ptr != '\n') {
475 crondlog("\111failed user %s parsing %s\n", user, base); 475 crondlog("\111failed user %s parsing %s\n", user, base);
476 return (NULL); 476 return NULL;
477 } 477 }
478 478
479 while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') { 479 while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') {
@@ -490,7 +490,7 @@ static char *ParseField(char *user, char *ary, int modvalue, int off,
490 } 490 }
491#endif 491#endif
492 492
493 return (ptr); 493 return ptr;
494} 494}
495 495
496static void FixDayDow(CronLine * line) 496static void FixDayDow(CronLine * line)
@@ -777,7 +777,7 @@ static int TestJobs(time_t t1, time_t t2)
777 } 777 }
778 } 778 }
779 } 779 }
780 return (nJobs); 780 return nJobs;
781} 781}
782 782
783static void RunJobs(void) 783static void RunJobs(void)
@@ -843,7 +843,7 @@ static int CheckJobs(void)
843 } 843 }
844 nStillRunning += file->cf_Running; 844 nStillRunning += file->cf_Running;
845 } 845 }
846 return (nStillRunning); 846 return nStillRunning;
847} 847}
848 848
849 849
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index f1fee2c90..32973d630 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -491,9 +491,9 @@ int devfsd_main (int argc, char **argv)
491 491
492 if ( print_version || (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev) ) 492 if ( print_version || (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev) )
493 { 493 {
494 bb_printf( "%s v%s\nDaemon %s:\t%d\nKernel-side %s:\t%d\n", 494 printf( "%s v%s\nDaemon %s:\t%d\nKernel-side %s:\t%d\n",
495 applet_name,DEVFSD_VERSION,bb_msg_proto_rev, 495 applet_name,DEVFSD_VERSION,bb_msg_proto_rev,
496 DEVFSD_PROTOCOL_REVISION_DAEMON,bb_msg_proto_rev, proto_rev); 496 DEVFSD_PROTOCOL_REVISION_DAEMON,bb_msg_proto_rev, proto_rev);
497 if (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev) 497 if (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev)
498 bb_error_msg_and_die( "%s mismatch!",bb_msg_proto_rev); 498 bb_error_msg_and_die( "%s mismatch!",bb_msg_proto_rev);
499 exit(EXIT_SUCCESS); /* -v */ 499 exit(EXIT_SUCCESS); /* -v */
@@ -509,7 +509,7 @@ int devfsd_main (int argc, char **argv)
509 if (sigaction (SIGHUP, &new_action, NULL) != 0 || sigaction (SIGUSR1, &new_action, NULL) != 0 ) 509 if (sigaction (SIGHUP, &new_action, NULL) != 0 || sigaction (SIGUSR1, &new_action, NULL) != 0 )
510 devfsd_error_msg_and_die( "sigaction"); 510 devfsd_error_msg_and_die( "sigaction");
511 511
512 bb_printf("%s v%s started for %s\n",applet_name, DEVFSD_VERSION, mount_point); 512 printf("%s v%s started for %s\n",applet_name, DEVFSD_VERSION, mount_point);
513 513
514 /* Set umask so that mknod(2), open(2) and mkdir(2) have complete control over permissions */ 514 /* Set umask so that mknod(2), open(2) and mkdir(2) have complete control over permissions */
515 umask (0); 515 umask (0);
diff --git a/miscutils/last.c b/miscutils/last.c
index 9f9f639f2..668f0c17d 100644
--- a/miscutils/last.c
+++ b/miscutils/last.c
@@ -87,5 +87,5 @@ int last_main(int argc, char **argv)
87 ctime(&t_tmp) + 4); 87 ctime(&t_tmp) + 4);
88 } 88 }
89 89
90 bb_fflush_stdout_and_exit(EXIT_SUCCESS); 90 fflush_stdout_and_exit(EXIT_SUCCESS);
91} 91}
diff --git a/miscutils/less.c b/miscutils/less.c
index 11f1d8baa..de97ba6b9 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -76,7 +76,7 @@ static int num_files = 1;
76static int past_eof; 76static int past_eof;
77 77
78/* Command line options */ 78/* Command line options */
79static unsigned long flags; 79static unsigned flags;
80#define FLAG_E 1 80#define FLAG_E 1
81#define FLAG_M (1<<1) 81#define FLAG_M (1<<1)
82#define FLAG_m (1<<2) 82#define FLAG_m (1<<2)
@@ -185,12 +185,12 @@ static void clear_line(void)
185/* This adds line numbers to every line, as the -N flag necessitates */ 185/* This adds line numbers to every line, as the -N flag necessitates */
186static void add_linenumbers(void) 186static void add_linenumbers(void)
187{ 187{
188 char current_line[256];
189 int i; 188 int i;
190 189
191 for (i = 0; i <= num_flines; i++) { 190 for (i = 0; i <= num_flines; i++) {
192 safe_strncpy(current_line, flines[i], 256); 191 char *new = xasprintf("%5d %s", i + 1, flines[i]);
193 flines[i] = xasprintf("%5d %s", i + 1, current_line); 192 free(flines[i]);
193 flines[i] = new;
194 } 194 }
195} 195}
196 196
@@ -206,7 +206,7 @@ static void data_readlines(void)
206 strcpy(current_line, ""); 206 strcpy(current_line, "");
207 fgets(current_line, 256, fp); 207 fgets(current_line, 256, fp);
208 if (fp != stdin) 208 if (fp != stdin)
209 xferror(fp, filename); 209 die_if_ferror(fp, filename);
210 flines = xrealloc(flines, (i+1) * sizeof(char *)); 210 flines = xrealloc(flines, (i+1) * sizeof(char *));
211 flines[i] = xstrdup(current_line); 211 flines[i] = xstrdup(current_line);
212 } 212 }
@@ -243,13 +243,18 @@ static void m_status_print(void)
243 if (!past_eof) { 243 if (!past_eof) {
244 if (!line_pos) { 244 if (!line_pos) {
245 if (num_files > 1) 245 if (num_files > 1)
246 printf("%s%s %s%i%s%i%s%i-%i/%i ", HIGHLIGHT, filename, "(file ", current_file, " of ", num_files, ") lines ", line_pos + 1, line_pos + height - 1, num_flines + 1); 246 printf("%s%s %s%i%s%i%s%i-%i/%i ", HIGHLIGHT,
247 filename, "(file ", current_file, " of ", num_files, ") lines ",
248 line_pos + 1, line_pos + height - 1, num_flines + 1);
247 else { 249 else {
248 printf("%s%s lines %i-%i/%i ", HIGHLIGHT, filename, line_pos + 1, line_pos + height - 1, num_flines + 1); 250 printf("%s%s lines %i-%i/%i ", HIGHLIGHT,
251 filename, line_pos + 1, line_pos + height - 1,
252 num_flines + 1);
249 } 253 }
250 } 254 }
251 else { 255 else {
252 printf("%s %s lines %i-%i/%i ", HIGHLIGHT, filename, line_pos + 1, line_pos + height - 1, num_flines + 1); 256 printf("%s %s lines %i-%i/%i ", HIGHLIGHT, filename,
257 line_pos + 1, line_pos + height - 1, num_flines + 1);
253 } 258 }
254 259
255 if (line_pos == num_flines - height + 2) { 260 if (line_pos == num_flines - height + 2) {
@@ -263,7 +268,8 @@ static void m_status_print(void)
263 } 268 }
264 } 269 }
265 else { 270 else {
266 printf("%s%s lines %i-%i/%i (END) ", HIGHLIGHT, filename, line_pos + 1, num_flines + 1, num_flines + 1); 271 printf("%s%s lines %i-%i/%i (END) ", HIGHLIGHT, filename,
272 line_pos + 1, num_flines + 1, num_flines + 1);
267 if ((num_files > 1) && (current_file != num_files)) 273 if ((num_files > 1) && (current_file != num_files))
268 printf("- Next: %s", files[current_file]); 274 printf("- Next: %s", files[current_file]);
269 printf("%s", NORMAL); 275 printf("%s", NORMAL);
@@ -300,7 +306,8 @@ static void status_print(void)
300 if (!line_pos) { 306 if (!line_pos) {
301 printf("%s%s %s", HIGHLIGHT, filename, NORMAL); 307 printf("%s%s %s", HIGHLIGHT, filename, NORMAL);
302 if (num_files > 1) 308 if (num_files > 1)
303 printf("%s%s%i%s%i%s%s", HIGHLIGHT, "(file ", current_file, " of ", num_files, ")", NORMAL); 309 printf("%s%s%i%s%i%s%s", HIGHLIGHT, "(file ",
310 current_file, " of ", num_files, ")", NORMAL);
304 } 311 }
305 else if (line_pos == num_flines - height + 2) { 312 else if (line_pos == num_flines - height + 2) {
306 printf("%s%s %s", HIGHLIGHT, "(END)", NORMAL); 313 printf("%s%s %s", HIGHLIGHT, "(END)", NORMAL);
@@ -602,7 +609,7 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
602 insert_highlights if action = 1, or has the escape sequences 609 insert_highlights if action = 1, or has the escape sequences
603 removed if action = 0, and then the line is returned. */ 610 removed if action = 0, and then the line is returned. */
604 int match_status; 611 int match_status;
605 char *line2 = (char *) xmalloc((sizeof(char) * (strlen(line) + 1)) + 64); 612 char *line2 = xmalloc((sizeof(char) * (strlen(line) + 1)) + 64);
606 char *growline = ""; 613 char *growline = "";
607 regmatch_t match_structs; 614 regmatch_t match_structs;
608 615
@@ -616,10 +623,16 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
616 match_found = 1; 623 match_found = 1;
617 624
618 if (action) { 625 if (action) {
619 growline = xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL); 626 growline = xasprintf("%s%.*s%s%.*s%s", growline,
627 match_structs.rm_so, line2, HIGHLIGHT,
628 match_structs.rm_eo - match_structs.rm_so,
629 line2 + match_structs.rm_so, NORMAL);
620 } 630 }
621 else { 631 else {
622 growline = xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so); 632 growline = xasprintf("%s%.*s%.*s", growline,
633 match_structs.rm_so - 4, line2,
634 match_structs.rm_eo - match_structs.rm_so,
635 line2 + match_structs.rm_so);
623 } 636 }
624 637
625 line2 += match_structs.rm_eo; 638 line2 += match_structs.rm_eo;
diff --git a/miscutils/mountpoint.c b/miscutils/mountpoint.c
index dbc8fe0e9..b1bcab698 100644
--- a/miscutils/mountpoint.c
+++ b/miscutils/mountpoint.c
@@ -13,6 +13,8 @@
13 13
14int mountpoint_main(int argc, char **argv) 14int mountpoint_main(int argc, char **argv)
15{ 15{
16 struct stat st;
17 char *arg;
16 int opt = getopt32(argc, argv, "qdx"); 18 int opt = getopt32(argc, argv, "qdx");
17#define OPT_q (1) 19#define OPT_q (1)
18#define OPT_d (2) 20#define OPT_d (2)
@@ -20,47 +22,44 @@ int mountpoint_main(int argc, char **argv)
20 22
21 if (optind != argc - 1) 23 if (optind != argc - 1)
22 bb_show_usage(); 24 bb_show_usage();
23 {
24 char *arg = argv[optind];
25 struct stat st;
26 25
27 if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) { 26 arg = argv[optind];
28 if (opt & OPT_x) {
29 if (S_ISBLK(st.st_mode))
30 {
31 bb_printf("%u:%u\n", major(st.st_rdev),
32 minor(st.st_rdev));
33 return EXIT_SUCCESS;
34 } else {
35 if (opt & OPT_q)
36 putchar('\n');
37 else
38 bb_error_msg("%s: not a block device", arg);
39 }
40 return EXIT_FAILURE;
41 } else
42 if (S_ISDIR(st.st_mode)) {
43 dev_t st_dev = st.st_dev;
44 ino_t st_ino = st.st_ino;
45 char *p = xasprintf("%s/..", arg);
46 27
47 if (stat(p, &st) == 0) { 28 if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) {
48 short ret = (st_dev != st.st_dev) || 29 if (opt & OPT_x) {
49 (st_dev == st.st_dev && st_ino == st.st_ino); 30 if (S_ISBLK(st.st_mode)) {
50 if (opt & OPT_d) 31 printf("%u:%u\n", major(st.st_rdev),
51 bb_printf("%u:%u\n", major(st_dev), minor(st_dev)); 32 minor(st.st_rdev));
52 else if (!(opt & OPT_q)) 33 return EXIT_SUCCESS;
53 bb_printf("%s is %sa mountpoint\n", arg, ret?"":"not ");
54 return !ret;
55 }
56 } else { 34 } else {
57 if (!(opt & OPT_q)) 35 if (opt & OPT_q)
58 bb_error_msg("%s: not a directory", arg); 36 putchar('\n');
59 return EXIT_FAILURE; 37 else
38 bb_error_msg("%s: not a block device", arg);
60 } 39 }
40 return EXIT_FAILURE;
41 } else
42 if (S_ISDIR(st.st_mode)) {
43 dev_t st_dev = st.st_dev;
44 ino_t st_ino = st.st_ino;
45 char *p = xasprintf("%s/..", arg);
46
47 if (stat(p, &st) == 0) {
48 int ret = (st_dev != st.st_dev) ||
49 (st_dev == st.st_dev && st_ino == st.st_ino);
50 if (opt & OPT_d)
51 printf("%u:%u\n", major(st_dev), minor(st_dev));
52 else if (!(opt & OPT_q))
53 printf("%s is %sa mountpoint\n", arg, ret?"":"not ");
54 return !ret;
55 }
56 } else {
57 if (!(opt & OPT_q))
58 bb_error_msg("%s: not a directory", arg);
59 return EXIT_FAILURE;
61 } 60 }
62 if (!(opt & OPT_q))
63 bb_perror_msg("%s", arg);
64 return EXIT_FAILURE;
65 } 61 }
62 if (!(opt & OPT_q))
63 bb_perror_msg("%s", arg);
64 return EXIT_FAILURE;
66} 65}
diff --git a/miscutils/rx.c b/miscutils/rx.c
index 00951b711..f723c1676 100644
--- a/miscutils/rx.c
+++ b/miscutils/rx.c
@@ -286,5 +286,5 @@ int rx_main(int argc, char **argv)
286 if (n < 0) 286 if (n < 0)
287 bb_error_msg_and_die("\nreceive failed:\n %s", error_buf); 287 bb_error_msg_and_die("\nreceive failed:\n %s", error_buf);
288 288
289 bb_fflush_stdout_and_exit(EXIT_SUCCESS); 289 fflush_stdout_and_exit(EXIT_SUCCESS);
290} 290}
diff --git a/miscutils/strings.c b/miscutils/strings.c
index 1ff41ad9c..dae17315e 100644
--- a/miscutils/strings.c
+++ b/miscutils/strings.c
@@ -84,5 +84,5 @@ PIPE:
84 if (ENABLE_FEATURE_CLEAN_UP) 84 if (ENABLE_FEATURE_CLEAN_UP)
85 free(string); 85 free(string);
86 86
87 bb_fflush_stdout_and_exit(status); 87 fflush_stdout_and_exit(status);
88} 88}