aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/basename.c7
-rw-r--r--coreutils/cat.c8
-rw-r--r--coreutils/chgrp.c3
-rw-r--r--coreutils/chmod.c3
-rw-r--r--coreutils/chown.c3
-rw-r--r--coreutils/chroot.c5
-rw-r--r--coreutils/cp.c3
-rw-r--r--coreutils/cut.c3
-rw-r--r--coreutils/dd.c5
-rw-r--r--coreutils/dirname.c6
-rw-r--r--coreutils/false.c3
-rw-r--r--coreutils/hostid.c6
-rw-r--r--coreutils/length.c13
-rw-r--r--coreutils/ln.c3
-rw-r--r--coreutils/logname.c14
-rw-r--r--coreutils/ls.c5
-rw-r--r--coreutils/mkdir.c8
-rw-r--r--coreutils/mkfifo.c6
-rw-r--r--coreutils/pwd.c7
-rw-r--r--coreutils/rm.c8
-rw-r--r--coreutils/rmdir.c10
-rw-r--r--coreutils/seq.c19
-rw-r--r--coreutils/sleep.c16
-rw-r--r--coreutils/sort.c3
-rw-r--r--coreutils/sync.c4
-rw-r--r--coreutils/test.c7
-rw-r--r--coreutils/true.c3
-rw-r--r--coreutils/tty.c6
-rw-r--r--coreutils/usleep.c5
-rw-r--r--coreutils/whoami.c9
-rw-r--r--coreutils/yes.c17
31 files changed, 124 insertions, 94 deletions
diff --git a/coreutils/basename.c b/coreutils/basename.c
index 46f7122c8..f4307d6ce 100644
--- a/coreutils/basename.c
+++ b/coreutils/basename.c
@@ -20,11 +20,10 @@
20 * 3) Save some space by using strcmp(). Calling strncmp() here was silly. 20 * 3) Save some space by using strcmp(). Calling strncmp() here was silly.
21 */ 21 */
22 22
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26#include "busybox.h" 23#include "busybox.h"
27 24
25/* This is a NOFORK applet. Be very careful! */
26
28int basename_main(int argc, char **argv); 27int basename_main(int argc, char **argv);
29int basename_main(int argc, char **argv) 28int basename_main(int argc, char **argv)
30{ 29{
@@ -47,5 +46,5 @@ int basename_main(int argc, char **argv)
47 46
48 puts(s); 47 puts(s);
49 48
50 fflush_stdout_and_exit(EXIT_SUCCESS); 49 return fflush(stdout);
51} 50}
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 7bab325ef..eb141dc79 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -12,17 +12,23 @@
12 12
13#include "busybox.h" 13#include "busybox.h"
14 14
15/* This is a NOFORK applet. Be very careful! */
16
17
15int bb_cat(char **argv) 18int bb_cat(char **argv)
16{ 19{
17 static const char *const argv_dash[] = { "-", NULL }; 20 static const char *const argv_dash[] = { "-", NULL };
21
18 FILE *f; 22 FILE *f;
19 int retval = EXIT_SUCCESS; 23 int retval = EXIT_SUCCESS;
20 24
21 if (!*argv) argv = (char**) &argv_dash; 25 if (!*argv)
26 argv = (char**) &argv_dash;
22 27
23 do { 28 do {
24 f = fopen_or_warn_stdin(*argv); 29 f = fopen_or_warn_stdin(*argv);
25 if (f) { 30 if (f) {
31 /* This is not an xfunc - never exits */
26 off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); 32 off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
27 fclose_if_not_stdin(f); 33 fclose_if_not_stdin(f);
28 if (r >= 0) 34 if (r >= 0)
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c
index cfb8c15b2..48014ecdf 100644
--- a/coreutils/chgrp.c
+++ b/coreutils/chgrp.c
@@ -13,6 +13,9 @@
13 13
14#include "busybox.h" 14#include "busybox.h"
15 15
16/* This is a NOEXEC applet. Be very careful! */
17
18
16int chgrp_main(int argc, char **argv); 19int chgrp_main(int argc, char **argv);
17int chgrp_main(int argc, char **argv) 20int chgrp_main(int argc, char **argv)
18{ 21{
diff --git a/coreutils/chmod.c b/coreutils/chmod.c
index 9a73218a1..aa3625877 100644
--- a/coreutils/chmod.c
+++ b/coreutils/chmod.c
@@ -16,6 +16,9 @@
16 16
17#include "busybox.h" 17#include "busybox.h"
18 18
19/* This is a NOEXEC applet. Be very careful! */
20
21
19#define OPT_RECURSE (option_mask32 & 1) 22#define OPT_RECURSE (option_mask32 & 1)
20#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 2) SKIP_DESKTOP(0)) 23#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 2) SKIP_DESKTOP(0))
21#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0)) 24#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
diff --git a/coreutils/chown.c b/coreutils/chown.c
index e64a39c3e..71ba81247 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -13,6 +13,9 @@
13 13
14#include "busybox.h" 14#include "busybox.h"
15 15
16/* This is a NOEXEC applet. Be very careful! */
17
18
16#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP")) 19#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
17#define BIT_RECURSE 1 20#define BIT_RECURSE 1
18#define OPT_RECURSE (option_mask32 & 1) 21#define OPT_RECURSE (option_mask32 & 1)
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index fcd70f21a..874ee917e 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -27,8 +27,9 @@ int chroot_main(int argc, char **argv)
27 ++argv; 27 ++argv;
28 if (argc == 2) { 28 if (argc == 2) {
29 argv -= 2; 29 argv -= 2;
30 if (!(*argv = getenv("SHELL"))) { 30 argv[0] = getenv("SHELL");
31 *argv = (char *) DEFAULT_SHELL; 31 if (!argv[0]) {
32 argv[0] = (char *) DEFAULT_SHELL;
32 } 33 }
33 argv[1] = (char *) "-i"; 34 argv[1] = (char *) "-i";
34 } 35 }
diff --git a/coreutils/cp.c b/coreutils/cp.c
index a80e0d286..8c0937971 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -18,6 +18,9 @@
18#include "busybox.h" 18#include "busybox.h"
19#include "libcoreutils/coreutils.h" 19#include "libcoreutils/coreutils.h"
20 20
21/* This is a NOEXEC applet. Be very careful! */
22
23
21int cp_main(int argc, char **argv); 24int cp_main(int argc, char **argv);
22int cp_main(int argc, char **argv) 25int cp_main(int argc, char **argv)
23{ 26{
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 22014fcfb..b9ea3127c 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -11,6 +11,9 @@
11 11
12#include "busybox.h" 12#include "busybox.h"
13 13
14/* This is a NOEXEC applet. Be very careful! */
15
16
14/* option vars */ 17/* option vars */
15static const char optstring[] = "b:c:f:d:sn"; 18static const char optstring[] = "b:c:f:d:sn";
16#define CUT_OPT_BYTE_FLGS (1<<0) 19#define CUT_OPT_BYTE_FLGS (1<<0)
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 4507b5e0c..34a325ea6 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -8,8 +8,11 @@
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */ 9 */
10 10
11#include "busybox.h"
12#include <signal.h> /* For FEATURE_DD_SIGNAL_HANDLING */ 11#include <signal.h> /* For FEATURE_DD_SIGNAL_HANDLING */
12#include "busybox.h"
13
14/* This is a NOEXEC applet. Be very careful! */
15
13 16
14static const struct suffix_mult dd_suffixes[] = { 17static const struct suffix_mult dd_suffixes[] = {
15 { "c", 1 }, 18 { "c", 1 },
diff --git a/coreutils/dirname.c b/coreutils/dirname.c
index 4ecde3147..7c5484bfd 100644
--- a/coreutils/dirname.c
+++ b/coreutils/dirname.c
@@ -10,10 +10,10 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/dirname.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/dirname.html */
12 12
13#include <stdio.h>
14#include <stdlib.h>
15#include "busybox.h" 13#include "busybox.h"
16 14
15/* This is a NOFORK applet. Be very careful! */
16
17int dirname_main(int argc, char **argv); 17int dirname_main(int argc, char **argv);
18int dirname_main(int argc, char **argv) 18int dirname_main(int argc, char **argv)
19{ 19{
@@ -23,5 +23,5 @@ int dirname_main(int argc, char **argv)
23 23
24 puts(dirname(argv[1])); 24 puts(dirname(argv[1]));
25 25
26 fflush_stdout_and_exit(EXIT_SUCCESS); 26 return fflush(stdout);
27} 27}
diff --git a/coreutils/false.c b/coreutils/false.c
index 2a26e0e28..90d6a0162 100644
--- a/coreutils/false.c
+++ b/coreutils/false.c
@@ -10,9 +10,10 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/false.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/false.html */
12 12
13#include <stdlib.h>
14#include "busybox.h" 13#include "busybox.h"
15 14
15/* This is a NOFORK applet. Be very careful! */
16
16int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv); 17int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv);
17int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv) 18int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
18{ 19{
diff --git a/coreutils/hostid.c b/coreutils/hostid.c
index 51a76c631..e14f6ca57 100644
--- a/coreutils/hostid.c
+++ b/coreutils/hostid.c
@@ -9,10 +9,10 @@
9 9
10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
11 11
12#include <stdlib.h>
13#include <unistd.h>
14#include "busybox.h" 12#include "busybox.h"
15 13
14/* This is a NOFORK applet. Be very careful! */
15
16int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv); 16int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv);
17int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv) 17int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv)
18{ 18{
@@ -22,5 +22,5 @@ int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv)
22 22
23 printf("%lx\n", gethostid()); 23 printf("%lx\n", gethostid());
24 24
25 fflush_stdout_and_exit(EXIT_SUCCESS); 25 return fflush(stdout);
26} 26}
diff --git a/coreutils/length.c b/coreutils/length.c
index 1dc122cc1..b3a9d4903 100644
--- a/coreutils/length.c
+++ b/coreutils/length.c
@@ -2,19 +2,18 @@
2 2
3/* BB_AUDIT SUSv3 N/A -- Apparently a busybox (obsolete?) extension. */ 3/* BB_AUDIT SUSv3 N/A -- Apparently a busybox (obsolete?) extension. */
4 4
5#include <stdlib.h>
6#include <string.h>
7#include <stdio.h>
8#include "busybox.h" 5#include "busybox.h"
9 6
7/* This is a NOFORK applet. Be very careful! */
8
10int length_main(int argc, char **argv); 9int length_main(int argc, char **argv);
11int length_main(int argc, char **argv) 10int length_main(int argc, char **argv)
12{ 11{
13 if ((argc != 2) || (**(++argv) == '-')) { 12 if ((argc != 2) || (**(++argv) == '-')) {
14 bb_show_usage(); 13 bb_show_usage();
15 } 14 }
16 15
17 printf("%lu\n", (unsigned long)strlen(*argv)); 16 printf("%u\n", (unsigned)strlen(*argv));
18 17
19 fflush_stdout_and_exit(EXIT_SUCCESS); 18 return fflush(stdout);
20} 19}
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 720713475..fd4eacec2 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -13,6 +13,9 @@
13 13
14#include "busybox.h" 14#include "busybox.h"
15 15
16/* This is a NOEXEC applet. Be very careful! */
17
18
16#define LN_SYMLINK 1 19#define LN_SYMLINK 1
17#define LN_FORCE 2 20#define LN_FORCE 2
18#define LN_NODEREFERENCE 4 21#define LN_NODEREFERENCE 4
diff --git a/coreutils/logname.c b/coreutils/logname.c
index 743e2291c..aba6ce3c6 100644
--- a/coreutils/logname.c
+++ b/coreutils/logname.c
@@ -20,23 +20,23 @@
20 * a diagnostic message and an error return. 20 * a diagnostic message and an error return.
21 */ 21 */
22 22
23#include <stdio.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include "busybox.h" 23#include "busybox.h"
27 24
25/* This is a NOFORK applet. Be very careful! */
26
28int logname_main(int argc, char ATTRIBUTE_UNUSED **argv); 27int logname_main(int argc, char ATTRIBUTE_UNUSED **argv);
29int logname_main(int argc, char ATTRIBUTE_UNUSED **argv) 28int logname_main(int argc, char ATTRIBUTE_UNUSED **argv)
30{ 29{
31 const char *p; 30 char buf[128];
32 31
33 if (argc > 1) { 32 if (argc > 1) {
34 bb_show_usage(); 33 bb_show_usage();
35 } 34 }
36 35
37 if ((p = getlogin()) != NULL) { 36 /* Using _r function - avoid pulling in static buffer from libc */
38 puts(p); 37 if (getlogin_r(buf, sizeof(buf)) == 0) {
39 fflush_stdout_and_exit(EXIT_SUCCESS); 38 puts(buf);
39 return fflush(stdout);
40 } 40 }
41 41
42 bb_perror_msg_and_die("getlogin"); 42 bb_perror_msg_and_die("getlogin");
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 34836ee29..7bbb19d6c 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -29,8 +29,11 @@
29 * 1. requires lstat (BSD) - how do you do it without? 29 * 1. requires lstat (BSD) - how do you do it without?
30 */ 30 */
31 31
32#include "busybox.h"
33#include <getopt.h> 32#include <getopt.h>
33#include "busybox.h"
34
35/* This is a NOEXEC applet. Be very careful! */
36
34 37
35enum { 38enum {
36 39
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 690e4ab40..5a6c9d077 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -19,19 +19,19 @@
19/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support. 19/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
20 */ 20 */
21 21
22#include <stdlib.h>
23#include <unistd.h>
24#include <getopt.h> /* struct option */ 22#include <getopt.h> /* struct option */
25#include "busybox.h" 23#include "busybox.h"
26 24
25/* This is a NOFORK applet. Be very careful! */
26
27#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS 27#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
28static const struct option mkdir_long_options[] = { 28static const struct option mkdir_long_options[] = {
29 { "mode", 1, NULL, 'm' }, 29 { "mode" , 1, NULL, 'm' },
30 { "parents", 0, NULL, 'p' }, 30 { "parents", 0, NULL, 'p' },
31#if ENABLE_SELINUX 31#if ENABLE_SELINUX
32 { "context", 1, NULL, 'Z' }, 32 { "context", 1, NULL, 'Z' },
33#endif 33#endif
34 { 0, 0, 0, 0 } 34 { NULL, 0, NULL, 0 }
35}; 35};
36#endif 36#endif
37 37
diff --git a/coreutils/mkfifo.c b/coreutils/mkfifo.c
index 6d8aa413e..7dcc50fa9 100644
--- a/coreutils/mkfifo.c
+++ b/coreutils/mkfifo.c
@@ -10,9 +10,6 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */
12 12
13#include <stdlib.h>
14#include <unistd.h>
15#include <sys/types.h>
16#include "busybox.h" 13#include "busybox.h"
17#include "libcoreutils/coreutils.h" 14#include "libcoreutils/coreutils.h"
18 15
@@ -24,7 +21,8 @@ int mkfifo_main(int argc, char **argv)
24 21
25 mode = getopt_mk_fifo_nod(argc, argv); 22 mode = getopt_mk_fifo_nod(argc, argv);
26 23
27 if (!*(argv += optind)) { 24 argv += optind;
25 if (!*argv) {
28 bb_show_usage(); 26 bb_show_usage();
29 } 27 }
30 28
diff --git a/coreutils/pwd.c b/coreutils/pwd.c
index d96f6a8e5..a93b8f115 100644
--- a/coreutils/pwd.c
+++ b/coreutils/pwd.c
@@ -7,10 +7,10 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <stdio.h>
11#include <stdlib.h>
12#include "busybox.h" 10#include "busybox.h"
13 11
12/* This is a NOFORK applet. Be very careful! */
13
14int pwd_main(int argc, char **argv); 14int pwd_main(int argc, char **argv);
15int pwd_main(int argc, char **argv) 15int pwd_main(int argc, char **argv)
16{ 16{
@@ -19,7 +19,8 @@ int pwd_main(int argc, char **argv)
19 buf = xrealloc_getcwd_or_warn(NULL); 19 buf = xrealloc_getcwd_or_warn(NULL);
20 if (buf != NULL) { 20 if (buf != NULL) {
21 puts(buf); 21 puts(buf);
22 fflush_stdout_and_exit(EXIT_SUCCESS); 22 free(buf);
23 return fflush(stdout);
23 } 24 }
24 25
25 return EXIT_FAILURE; 26 return EXIT_FAILURE;
diff --git a/coreutils/rm.c b/coreutils/rm.c
index 1883feed8..6f32e7dc5 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -15,9 +15,10 @@
15 * Size reduction. 15 * Size reduction.
16 */ 16 */
17 17
18#include <unistd.h>
19#include "busybox.h" 18#include "busybox.h"
20 19
20/* This is a NOFORK applet. Be very careful! */
21
21int rm_main(int argc, char **argv); 22int rm_main(int argc, char **argv);
22int rm_main(int argc, char **argv) 23int rm_main(int argc, char **argv)
23{ 24{
@@ -27,14 +28,15 @@ int rm_main(int argc, char **argv)
27 28
28 opt_complementary = "f-i:i-f"; 29 opt_complementary = "f-i:i-f";
29 opt = getopt32(argc, argv, "fiRr"); 30 opt = getopt32(argc, argv, "fiRr");
31 argv += optind;
30 if(opt & 1) 32 if(opt & 1)
31 flags |= FILEUTILS_FORCE; 33 flags |= FILEUTILS_FORCE;
32 if(opt & 2) 34 if(opt & 2)
33 flags |= FILEUTILS_INTERACTIVE; 35 flags |= FILEUTILS_INTERACTIVE;
34 if(opt & 12) 36 if(opt & 12)
35 flags |= FILEUTILS_RECUR; 37 flags |= FILEUTILS_RECUR;
36 38
37 if (*(argv += optind) != NULL) { 39 if (*argv != NULL) {
38 do { 40 do {
39 const char *base = bb_get_last_path_component(*argv); 41 const char *base = bb_get_last_path_component(*argv);
40 42
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c
index 8cbd6f1fa..7f3253017 100644
--- a/coreutils/rmdir.c
+++ b/coreutils/rmdir.c
@@ -10,11 +10,12 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
12 12
13#include <stdlib.h>
14#include <unistd.h>
15#include <libgen.h> 13#include <libgen.h>
16#include "busybox.h" 14#include "busybox.h"
17 15
16/* This is a NOFORK applet. Be very careful! */
17
18
18int rmdir_main(int argc, char **argv); 19int rmdir_main(int argc, char **argv);
19int rmdir_main(int argc, char **argv) 20int rmdir_main(int argc, char **argv)
20{ 21{
@@ -24,7 +25,6 @@ int rmdir_main(int argc, char **argv)
24 char *path; 25 char *path;
25 26
26 flags = getopt32(argc, argv, "p"); 27 flags = getopt32(argc, argv, "p");
27
28 argv += optind; 28 argv += optind;
29 29
30 if (!*argv) { 30 if (!*argv) {
@@ -37,7 +37,7 @@ int rmdir_main(int argc, char **argv)
37 /* Record if the first char was a '.' so we can use dirname later. */ 37 /* Record if the first char was a '.' so we can use dirname later. */
38 do_dot = (*path == '.'); 38 do_dot = (*path == '.');
39 39
40 do { 40 while (1) {
41 if (rmdir(path) < 0) { 41 if (rmdir(path) < 0) {
42 bb_perror_msg("'%s'", path); /* Match gnu rmdir msg. */ 42 bb_perror_msg("'%s'", path); /* Match gnu rmdir msg. */
43 status = EXIT_FAILURE; 43 status = EXIT_FAILURE;
@@ -53,7 +53,7 @@ int rmdir_main(int argc, char **argv)
53 } 53 }
54 } 54 }
55 break; 55 break;
56 } while (1); 56 }
57 57
58 } while (*++argv); 58 } while (*++argv);
59 59
diff --git a/coreutils/seq.c b/coreutils/seq.c
index e81a4660a..ef884d6ae 100644
--- a/coreutils/seq.c
+++ b/coreutils/seq.c
@@ -7,21 +7,22 @@
7 * Licensed under the GPL v2, see the file LICENSE in this tarball. 7 * Licensed under the GPL v2, see the file LICENSE in this tarball.
8 */ 8 */
9 9
10#include <stdio.h>
11#include <stdlib.h>
12#include "busybox.h" 10#include "busybox.h"
13 11
12/* This is a NOFORK applet. Be very careful! */
13
14
14int seq_main(int argc, char **argv); 15int seq_main(int argc, char **argv);
15int seq_main(int argc, char **argv) 16int seq_main(int argc, char **argv)
16{ 17{
17 double last, first, increment, i; 18 double last, increment, i;
18 19
19 first = increment = 1; 20 i = increment = 1;
20 switch (argc) { 21 switch (argc) {
21 case 4: 22 case 4:
22 increment = atof(argv[2]); 23 increment = atof(argv[2]);
23 case 3: 24 case 3:
24 first = atof(argv[1]); 25 i = atof(argv[1]);
25 case 2: 26 case 2:
26 last = atof(argv[argc-1]); 27 last = atof(argv[argc-1]);
27 break; 28 break;
@@ -30,12 +31,10 @@ int seq_main(int argc, char **argv)
30 } 31 }
31 32
32 /* You should note that this is pos-5.0.91 semantics, -- FK. */ 33 /* You should note that this is pos-5.0.91 semantics, -- FK. */
33 for (i = first; 34 while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) {
34 (increment > 0 && i <= last) || (increment < 0 && i >=last);
35 i += increment)
36 {
37 printf("%g\n", i); 35 printf("%g\n", i);
36 i += increment;
38 } 37 }
39 38
40 return EXIT_SUCCESS; 39 return fflush(stdout);
41} 40}
diff --git a/coreutils/sleep.c b/coreutils/sleep.c
index b89b0fe9c..592005bab 100644
--- a/coreutils/sleep.c
+++ b/coreutils/sleep.c
@@ -18,12 +18,12 @@
18 * time suffixes for seconds, minutes, hours, and days. 18 * time suffixes for seconds, minutes, hours, and days.
19 */ 19 */
20 20
21#include <stdlib.h>
22#include <limits.h>
23#include <unistd.h>
24#include "busybox.h" 21#include "busybox.h"
25 22
26#ifdef CONFIG_FEATURE_FANCY_SLEEP 23/* This is a NOFORK applet. Be very careful! */
24
25
26#if ENABLE_FEATURE_FANCY_SLEEP
27static const struct suffix_mult sfx[] = { 27static const struct suffix_mult sfx[] = {
28 { "s", 1 }, 28 { "s", 1 },
29 { "m", 60 }, 29 { "m", 60 },
@@ -36,9 +36,9 @@ static const struct suffix_mult sfx[] = {
36int sleep_main(int argc, char **argv); 36int sleep_main(int argc, char **argv);
37int sleep_main(int argc, char **argv) 37int sleep_main(int argc, char **argv)
38{ 38{
39 unsigned int duration; 39 unsigned duration;
40 40
41#ifdef CONFIG_FEATURE_FANCY_SLEEP 41#if ENABLE_FEATURE_FANCY_SLEEP
42 42
43 if (argc < 2) { 43 if (argc < 2) {
44 bb_show_usage(); 44 bb_show_usage();
@@ -50,7 +50,7 @@ int sleep_main(int argc, char **argv)
50 duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx); 50 duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
51 } while (*++argv); 51 } while (*++argv);
52 52
53#else /* CONFIG_FEATURE_FANCY_SLEEP */ 53#else /* FEATURE_FANCY_SLEEP */
54 54
55 if (argc != 2) { 55 if (argc != 2) {
56 bb_show_usage(); 56 bb_show_usage();
@@ -58,7 +58,7 @@ int sleep_main(int argc, char **argv)
58 58
59 duration = xatou(argv[1]); 59 duration = xatou(argv[1]);
60 60
61#endif /* CONFIG_FEATURE_FANCY_SLEEP */ 61#endif /* FEATURE_FANCY_SLEEP */
62 62
63 if (sleep(duration)) { 63 if (sleep(duration)) {
64 bb_perror_nomsg_and_die(); 64 bb_perror_nomsg_and_die();
diff --git a/coreutils/sort.c b/coreutils/sort.c
index dad542964..06a6cbf70 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -14,6 +14,9 @@
14 14
15#include "busybox.h" 15#include "busybox.h"
16 16
17/* This is a NOEXEC applet. Be very careful! */
18
19
17/* 20/*
18 sort [-m][-o output][-bdfinru][-t char][-k keydef]... [file...] 21 sort [-m][-o output][-bdfinru][-t char][-k keydef]... [file...]
19 sort -c [-bdfinru][-t char][-k keydef][file] 22 sort -c [-bdfinru][-t char][-k keydef][file]
diff --git a/coreutils/sync.c b/coreutils/sync.c
index 536c57a17..e52ab768d 100644
--- a/coreutils/sync.c
+++ b/coreutils/sync.c
@@ -9,10 +9,10 @@
9 9
10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
11 11
12#include <stdlib.h>
13#include <unistd.h>
14#include "busybox.h" 12#include "busybox.h"
15 13
14/* This is a NOFORK applet. Be very careful! */
15
16int sync_main(int argc, char **argv); 16int sync_main(int argc, char **argv);
17int sync_main(int argc, char **argv) 17int sync_main(int argc, char **argv)
18{ 18{
diff --git a/coreutils/test.c b/coreutils/test.c
index d5babefce..e9b627638 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -21,12 +21,11 @@
21 */ 21 */
22 22
23#include "busybox.h" 23#include "busybox.h"
24#include <unistd.h>
25#include <ctype.h>
26#include <errno.h>
27#include <string.h>
28#include <setjmp.h> 24#include <setjmp.h>
29 25
26/* This is a NOEXEC applet. Be very careful! */
27
28
30/* test(1) accepts the following grammar: 29/* test(1) accepts the following grammar:
31 oexpr ::= aexpr | aexpr "-o" oexpr ; 30 oexpr ::= aexpr | aexpr "-o" oexpr ;
32 aexpr ::= nexpr | nexpr "-a" aexpr ; 31 aexpr ::= nexpr | nexpr "-a" aexpr ;
diff --git a/coreutils/true.c b/coreutils/true.c
index b2f3a9bad..eee621331 100644
--- a/coreutils/true.c
+++ b/coreutils/true.c
@@ -10,9 +10,10 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/true.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/true.html */
12 12
13#include <stdlib.h>
14#include "busybox.h" 13#include "busybox.h"
15 14
15/* This is a NOFORK applet. Be very careful! */
16
16int true_main(int argc, char **argv); 17int true_main(int argc, char **argv);
17int true_main(int argc, char **argv) 18int true_main(int argc, char **argv)
18{ 19{
diff --git a/coreutils/tty.c b/coreutils/tty.c
index c28aa33d7..d4c179fca 100644
--- a/coreutils/tty.c
+++ b/coreutils/tty.c
@@ -10,9 +10,6 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/tty.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/tty.html */
12 12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include "busybox.h" 13#include "busybox.h"
17 14
18int tty_main(int argc, char **argv); 15int tty_main(int argc, char **argv);
@@ -31,7 +28,8 @@ int tty_main(int argc, char **argv)
31 28
32 retval = 0; 29 retval = 0;
33 30
34 if ((s = ttyname(0)) == NULL) { 31 s = ttyname(0);
32 if (s == NULL) {
35 /* According to SUSv3, ttyname can on fail with EBADF or ENOTTY. 33 /* According to SUSv3, ttyname can on fail with EBADF or ENOTTY.
36 * We know the file descriptor is good, so failure means not a tty. */ 34 * We know the file descriptor is good, so failure means not a tty. */
37 s = "not a tty"; 35 s = "not a tty";
diff --git a/coreutils/usleep.c b/coreutils/usleep.c
index 7dd914638..2baf2bc87 100644
--- a/coreutils/usleep.c
+++ b/coreutils/usleep.c
@@ -9,11 +9,10 @@
9 9
10/* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */ 10/* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
11 11
12#include <stdlib.h>
13#include <limits.h>
14#include <unistd.h>
15#include "busybox.h" 12#include "busybox.h"
16 13
14/* This is a NOFORK applet. Be very careful! */
15
17int usleep_main(int argc, char **argv); 16int usleep_main(int argc, char **argv);
18int usleep_main(int argc, char **argv) 17int usleep_main(int argc, char **argv)
19{ 18{
diff --git a/coreutils/whoami.c b/coreutils/whoami.c
index 3185817b6..25757f633 100644
--- a/coreutils/whoami.c
+++ b/coreutils/whoami.c
@@ -9,11 +9,10 @@
9 9
10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
11 11
12#include <stdio.h>
13#include <stdlib.h>
14#include <unistd.h>
15#include "busybox.h" 12#include "busybox.h"
16 13
14/* This is a NOFORK applet. Be very careful! */
15
17int whoami_main(int argc, char **argv); 16int whoami_main(int argc, char **argv);
18int whoami_main(int argc, char **argv) 17int whoami_main(int argc, char **argv)
19{ 18{
@@ -21,6 +20,6 @@ int whoami_main(int argc, char **argv)
21 bb_show_usage(); 20 bb_show_usage();
22 21
23 puts(bb_getpwuid(NULL, geteuid(), -1)); 22 puts(bb_getpwuid(NULL, geteuid(), -1));
24 /* exits on error */ 23
25 fflush_stdout_and_exit(EXIT_SUCCESS); 24 return fflush(stdout);
26} 25}
diff --git a/coreutils/yes.c b/coreutils/yes.c
index 2611c3e82..569764150 100644
--- a/coreutils/yes.c
+++ b/coreutils/yes.c
@@ -16,25 +16,26 @@
16 16
17#include "busybox.h" 17#include "busybox.h"
18 18
19/* This is a NOFORK applet. Be very careful! */
20
19int yes_main(int argc, char **argv); 21int yes_main(int argc, char **argv);
20int yes_main(int argc, char **argv) 22int yes_main(int argc, char **argv)
21{ 23{
22 static const char fmt_str[] = " %s";
23 const char *fmt;
24 char **first_arg; 24 char **first_arg;
25 25
26 *argv = (char*)"y"; 26 argv[0] = (char*)"y";
27 if (argc != 1) { 27 if (argc != 1) {
28 ++argv; 28 ++argv;
29 } 29 }
30 30
31 first_arg = argv; 31 first_arg = argv;
32 do { 32 do {
33 fmt = fmt_str + 1; 33 while (1) {
34 do { 34 fputs(*argv, stdout);
35 printf(fmt, *argv); 35 if (!*++argv)
36 fmt = fmt_str; 36 break;
37 } while (*++argv); 37 putchar(' ');
38 }
38 argv = first_arg; 39 argv = first_arg;
39 } while (putchar('\n') != EOF); 40 } while (putchar('\n') != EOF);
40 41