aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-02-13 09:44:44 +0000
committerRon Yorston <rmy@pobox.com>2018-02-13 09:44:44 +0000
commitdc19a361bd6c6df30338371532691bbc7f7126bb (patch)
tree1fb2cd646d54b5f8e425c4f11f3e09fc21d1966b /coreutils
parent096aee2bb468d1ab044de36e176ed1f6c7e3674d (diff)
parent3459024bf404af814cacfe90a0deb719e282ae62 (diff)
downloadbusybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.gz
busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.bz2
busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cat.c5
-rw-r--r--coreutils/chown.c4
-rw-r--r--coreutils/cksum.c47
-rw-r--r--coreutils/cp.c22
-rw-r--r--coreutils/dd.c44
-rw-r--r--coreutils/ls.c5
-rw-r--r--coreutils/mknod.c56
-rw-r--r--coreutils/mv.c3
-rw-r--r--coreutils/nice.c21
-rw-r--r--coreutils/od_bloaty.c10
-rw-r--r--coreutils/stat.c7
-rw-r--r--coreutils/uname.c6
12 files changed, 138 insertions, 92 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 7e35fa5ee..5f02233ca 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -168,9 +168,12 @@ static int catv(unsigned opts, char **argv)
168int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 168int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
169int cat_main(int argc UNUSED_PARAM, char **argv) 169int cat_main(int argc UNUSED_PARAM, char **argv)
170{ 170{
171#if ENABLE_FEATURE_CATV || ENABLE_FEATURE_CATN
171 unsigned opts; 172 unsigned opts;
172 173
173 opts = getopt32(argv, IF_FEATURE_CATV("^") 174 opts =
175#endif
176 getopt32(argv, IF_FEATURE_CATV("^")
174 /* -u is ignored ("unbuffered") */ 177 /* -u is ignored ("unbuffered") */
175 IF_FEATURE_CATV("etvA")IF_FEATURE_CATN("nb")"u" 178 IF_FEATURE_CATV("etvA")IF_FEATURE_CATN("nb")"u"
176 IF_FEATURE_CATV("\0" "Aetv" /* -A == -vet */) 179 IF_FEATURE_CATV("\0" "Aetv" /* -A == -vet */)
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 985d18d6f..6429fd030 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -128,9 +128,9 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
128 struct param_t param; 128 struct param_t param;
129 129
130#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS 130#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
131 opt = getopt32long(argv, "^" OPT_STR "\0" "=2", chown_longopts); 131 opt = getopt32long(argv, "^" OPT_STR "\0" "-2", chown_longopts);
132#else 132#else
133 opt = getopt32(argv, "^" OPT_STR "\0" "=2"); 133 opt = getopt32(argv, "^" OPT_STR "\0" "-2");
134#endif 134#endif
135 argv += optind; 135 argv += optind;
136 136
diff --git a/coreutils/cksum.c b/coreutils/cksum.c
index 059a33310..e46e249f2 100644
--- a/coreutils/cksum.c
+++ b/coreutils/cksum.c
@@ -31,9 +31,6 @@ int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
31int cksum_main(int argc UNUSED_PARAM, char **argv) 31int cksum_main(int argc UNUSED_PARAM, char **argv)
32{ 32{
33 uint32_t *crc32_table = crc32_filltable(NULL, 1); 33 uint32_t *crc32_table = crc32_filltable(NULL, 1);
34 uint32_t crc;
35 off_t length, filesize;
36 int bytes_read;
37 int exit_code = EXIT_SUCCESS; 34 int exit_code = EXIT_SUCCESS;
38 35
39#if ENABLE_DESKTOP 36#if ENABLE_DESKTOP
@@ -45,38 +42,42 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
45 42
46 setup_common_bufsiz(); 43 setup_common_bufsiz();
47 do { 44 do {
45 uint32_t crc;
46 off_t filesize;
48 int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input); 47 int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
49 48
50 if (fd < 0) { 49 if (fd < 0) {
51 exit_code = EXIT_FAILURE; 50 exit_code = EXIT_FAILURE;
52 continue; 51 continue;
53 } 52 }
54 crc = 0;
55 length = 0;
56 53
54 crc = 0;
55 filesize = 0;
57#define read_buf bb_common_bufsiz1 56#define read_buf bb_common_bufsiz1
58 while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) { 57 for (;;) {
59 length += bytes_read; 58 uoff_t t;
59 int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE);
60 if (bytes_read > 0) {
61 filesize += bytes_read;
62 } else {
63 /* Checksum filesize bytes, LSB first, and exit */
64 close(fd);
65 fd = -1; /* break flag */
66 t = filesize;
67 bytes_read = 0;
68 while (t != 0) {
69 read_buf[bytes_read++] = (uint8_t)t;
70 t >>= 8;
71 }
72 }
60 crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); 73 crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
74 if (fd < 0)
75 break;
61 } 76 }
62 close(fd);
63
64 filesize = length;
65 77
66 while (length) {
67 crc = (crc << 8) ^ crc32_table[(uint8_t)(crc >> 24) ^ (uint8_t)length];
68 /* must ensure that shift is unsigned! */
69 if (sizeof(length) <= sizeof(unsigned))
70 length = (unsigned)length >> 8;
71 else if (sizeof(length) <= sizeof(unsigned long))
72 length = (unsigned long)length >> 8;
73 else
74 length = (unsigned long long)length >> 8;
75 }
76 crc = ~crc; 78 crc = ~crc;
77 79 printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"),
78 printf((*argv ? "%"PRIu32" %"OFF_FMT"i %s\n" : "%"PRIu32" %"OFF_FMT"i\n"), 80 (unsigned)crc, filesize, *argv);
79 crc, filesize, *argv);
80 } while (*argv && *++argv); 81 } while (*argv && *++argv);
81 82
82 fflush_stdout_and_exit(exit_code); 83 fflush_stdout_and_exit(exit_code);
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 5b34c27e7..455bffbba 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -26,6 +26,7 @@
26//config: Also add support for --parents option. 26//config: Also add support for --parents option.
27 27
28//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) 28//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
29/* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */
29 30
30//kbuild:lib-$(CONFIG_CP) += cp.o 31//kbuild:lib-$(CONFIG_CP) += cp.o
31 32
@@ -47,6 +48,7 @@
47//usage: "\n -f Overwrite" 48//usage: "\n -f Overwrite"
48//usage: "\n -i Prompt before overwrite" 49//usage: "\n -i Prompt before overwrite"
49//usage: "\n -l,-s Create (sym)links" 50//usage: "\n -l,-s Create (sym)links"
51//usage: "\n -T Treat DEST as a normal file"
50//usage: "\n -u Copy only newer files" 52//usage: "\n -u Copy only newer files"
51 53
52#include "libbb.h" 54#include "libbb.h"
@@ -92,13 +94,18 @@ int cp_main(int argc, char **argv)
92 "no-dereference\0" No_argument "P" 94 "no-dereference\0" No_argument "P"
93 "recursive\0" No_argument "R" 95 "recursive\0" No_argument "R"
94 "symbolic-link\0" No_argument "s" 96 "symbolic-link\0" No_argument "s"
97 "no-target-directory\0" No_argument "T"
95 "verbose\0" No_argument "v" 98 "verbose\0" No_argument "v"
96 "update\0" No_argument "u" 99 "update\0" No_argument "u"
97 "remove-destination\0" No_argument "\xff" 100 "remove-destination\0" No_argument "\xff"
98 "parents\0" No_argument "\xfe" 101 "parents\0" No_argument "\xfe"
99 ); 102 );
100#else 103#else
101 flags = getopt32(argv, FILEUTILS_CP_OPTSTR); 104 flags = getopt32(argv, "^"
105 FILEUTILS_CP_OPTSTR
106 "\0"
107 "-2:l--s:s--l:Pd:rRd:Rd:apdR"
108 );
102#endif 109#endif
103 /* Options of cp from GNU coreutils 6.10: 110 /* Options of cp from GNU coreutils 6.10:
104 * -a, --archive 111 * -a, --archive
@@ -121,6 +128,8 @@ int cp_main(int argc, char **argv)
121 * remove each existing destination file before attempting to open 128 * remove each existing destination file before attempting to open
122 * --parents 129 * --parents
123 * use full source file name under DIRECTORY 130 * use full source file name under DIRECTORY
131 * -T, --no-target-directory
132 * treat DEST as a normal file
124 * NOT SUPPORTED IN BBOX: 133 * NOT SUPPORTED IN BBOX:
125 * --backup[=CONTROL] 134 * --backup[=CONTROL]
126 * make a backup of each existing destination file 135 * make a backup of each existing destination file
@@ -139,8 +148,6 @@ int cp_main(int argc, char **argv)
139 * override the usual backup suffix 148 * override the usual backup suffix
140 * -t, --target-directory=DIRECTORY 149 * -t, --target-directory=DIRECTORY
141 * copy all SOURCE arguments into DIRECTORY 150 * copy all SOURCE arguments into DIRECTORY
142 * -T, --no-target-directory
143 * treat DEST as a normal file
144 * -x, --one-file-system 151 * -x, --one-file-system
145 * stay on this file system 152 * stay on this file system
146 * -Z, --context=CONTEXT 153 * -Z, --context=CONTEXT
@@ -175,6 +182,12 @@ int cp_main(int argc, char **argv)
175 if (d_flags < 0) 182 if (d_flags < 0)
176 return EXIT_FAILURE; 183 return EXIT_FAILURE;
177 184
185 if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
186 if (!(s_flags & 2) && (d_flags & 2))
187 /* cp -T NOTDIR DIR */
188 bb_error_msg_and_die("'%s' is a directory", last);
189 }
190
178#if ENABLE_FEATURE_CP_LONG_OPTIONS 191#if ENABLE_FEATURE_CP_LONG_OPTIONS
179 //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", 192 //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
180 // flags, FILEUTILS_RMDEST, OPT_parents); 193 // flags, FILEUTILS_RMDEST, OPT_parents);
@@ -192,11 +205,14 @@ int cp_main(int argc, char **argv)
192 if (!((s_flags | d_flags) & 2) 205 if (!((s_flags | d_flags) & 2)
193 /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */ 206 /* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
194 || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags) 207 || ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
208 || (flags & FILEUTILS_NO_TARGET_DIR)
195 ) { 209 ) {
196 /* Do a simple copy */ 210 /* Do a simple copy */
197 dest = last; 211 dest = last;
198 goto DO_COPY; /* NB: argc==2 -> *++argv==last */ 212 goto DO_COPY; /* NB: argc==2 -> *++argv==last */
199 } 213 }
214 } else if (flags & FILEUTILS_NO_TARGET_DIR) {
215 bb_error_msg_and_die("too many arguments");
200 } 216 }
201 217
202 while (1) { 218 while (1) {
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 14d270a1e..178576752 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -37,7 +37,7 @@
37//config: elapsed time and speed. 37//config: elapsed time and speed.
38//config: 38//config:
39//config:config FEATURE_DD_IBS_OBS 39//config:config FEATURE_DD_IBS_OBS
40//config: bool "Enable ibs, obs and conv options" 40//config: bool "Enable ibs, obs, iflag and conv options"
41//config: default y 41//config: default y
42//config: depends on DD 42//config: depends on DD
43//config: help 43//config: help
@@ -57,7 +57,7 @@
57 57
58//usage:#define dd_trivial_usage 58//usage:#define dd_trivial_usage
59//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n" 59//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
60//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]") 60//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes|fullblock]")
61//usage:#define dd_full_usage "\n\n" 61//usage:#define dd_full_usage "\n\n"
62//usage: "Copy a file with converting and formatting\n" 62//usage: "Copy a file with converting and formatting\n"
63//usage: "\n if=FILE Read from FILE instead of stdin" 63//usage: "\n if=FILE Read from FILE instead of stdin"
@@ -79,6 +79,7 @@
79//usage: "\n conv=fsync Physically write data out before finishing" 79//usage: "\n conv=fsync Physically write data out before finishing"
80//usage: "\n conv=swab Swap every pair of bytes" 80//usage: "\n conv=swab Swap every pair of bytes"
81//usage: "\n iflag=skip_bytes skip=N is in bytes" 81//usage: "\n iflag=skip_bytes skip=N is in bytes"
82//usage: "\n iflag=fullblock Read full blocks"
82//usage: ) 83//usage: )
83//usage: IF_FEATURE_DD_STATUS( 84//usage: IF_FEATURE_DD_STATUS(
84//usage: "\n status=noxfer Suppress rate output" 85//usage: "\n status=noxfer Suppress rate output"
@@ -130,11 +131,12 @@ enum {
130 /* start of input flags */ 131 /* start of input flags */
131 FLAG_IFLAG_SHIFT = 5, 132 FLAG_IFLAG_SHIFT = 5,
132 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, 133 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
134 FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
133 /* end of input flags */ 135 /* end of input flags */
134 FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, 136 FLAG_TWOBUFS = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
135 FLAG_COUNT = 1 << 7, 137 FLAG_COUNT = 1 << 8,
136 FLAG_STATUS_NONE = 1 << 8, 138 FLAG_STATUS_NONE = 1 << 9,
137 FLAG_STATUS_NOXFER = 1 << 9, 139 FLAG_STATUS_NOXFER = 1 << 10,
138}; 140};
139 141
140static void dd_output_status(int UNUSED_PARAM cur_signal) 142static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -195,14 +197,18 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
195 ssize_t n = full_write_or_warn(buf, len, filename); 197 ssize_t n = full_write_or_warn(buf, len, filename);
196 if (n < 0) 198 if (n < 0)
197 return 1; 199 return 1;
198 if ((size_t)n == obs)
199 G.out_full++;
200 else if (n) /* > 0 */
201 G.out_part++;
202#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE 200#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
203 G.total_bytes += n; 201 G.total_bytes += n;
204#endif 202#endif
205 return 0; 203 if ((size_t)n == obs) {
204 G.out_full++;
205 return 0;
206 }
207 if ((size_t)n == len) {
208 G.out_part++;
209 return 0;
210 }
211 return 1;
206} 212}
207 213
208#if ENABLE_LFS 214#if ENABLE_LFS
@@ -251,7 +257,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
251 static const char conv_words[] ALIGN1 = 257 static const char conv_words[] ALIGN1 =
252 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; 258 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
253 static const char iflag_words[] ALIGN1 = 259 static const char iflag_words[] ALIGN1 =
254 "skip_bytes\0"; 260 "skip_bytes\0""fullblock\0";
255#endif 261#endif
256#if ENABLE_FEATURE_DD_STATUS 262#if ENABLE_FEATURE_DD_STATUS
257 static const char status_words[] ALIGN1 = 263 static const char status_words[] ALIGN1 =
@@ -290,6 +296,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
290 /* Partially implemented: */ 296 /* Partially implemented: */
291 //swab swap every pair of input bytes: will abort on non-even reads 297 //swab swap every pair of input bytes: will abort on non-even reads
292 OP_iflag_skip_bytes, 298 OP_iflag_skip_bytes,
299 OP_iflag_fullblock,
293#endif 300#endif
294 }; 301 };
295 smallint exitcode = EXIT_FAILURE; 302 smallint exitcode = EXIT_FAILURE;
@@ -456,7 +463,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
456 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; 463 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
457 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { 464 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
458 do { 465 do {
459 ssize_t n = safe_read(ifd, ibuf, blocksz); 466 ssize_t n;
467#if ENABLE_FEATURE_DD_IBS_OBS
468 if (G.flags & FLAG_FULLBLOCK)
469 n = full_read(ifd, ibuf, blocksz);
470 else
471#endif
472 n = safe_read(ifd, ibuf, blocksz);
460 if (n < 0) 473 if (n < 0)
461 goto die_infile; 474 goto die_infile;
462 if (n == 0) 475 if (n == 0)
@@ -477,6 +490,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
477 n = ibs; 490 n = ibs;
478 } 491 }
479 else 492 else
493#if ENABLE_FEATURE_DD_IBS_OBS
494 if (G.flags & FLAG_FULLBLOCK)
495 n = full_read(ifd, ibuf, ibs);
496 else
497#endif
480 n = safe_read(ifd, ibuf, ibs); 498 n = safe_read(ifd, ibuf, ibs);
481 if (n == 0) 499 if (n == 0)
482 break; 500 break;
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 22286d713..4cc9517b1 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -482,12 +482,11 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
482 int opt; 482 int opt;
483#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR 483#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
484 struct stat statbuf; 484 struct stat statbuf;
485 char append;
486#endif 485#endif
487
488#if ENABLE_FEATURE_LS_FILETYPES 486#if ENABLE_FEATURE_LS_FILETYPES
489 append = append_char(dn->dn_mode); 487 char append = append_char(dn->dn_mode);
490#endif 488#endif
489
491 opt = option_mask32; 490 opt = option_mask32;
492 491
493 /* Do readlink early, so that if it fails, error message 492 /* Do readlink early, so that if it fails, error message
diff --git a/coreutils/mknod.c b/coreutils/mknod.c
index 565b33d20..d57167f7d 100644
--- a/coreutils/mknod.c
+++ b/coreutils/mknod.c
@@ -20,7 +20,7 @@
20/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 20/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
21 21
22//usage:#define mknod_trivial_usage 22//usage:#define mknod_trivial_usage
23//usage: "[-m MODE] " IF_SELINUX("[-Z] ") "NAME TYPE MAJOR MINOR" 23//usage: "[-m MODE] " IF_SELINUX("[-Z] ") "NAME TYPE [MAJOR MINOR]"
24//usage:#define mknod_full_usage "\n\n" 24//usage:#define mknod_full_usage "\n\n"
25//usage: "Create a special file (block, character, or pipe)\n" 25//usage: "Create a special file (block, character, or pipe)\n"
26//usage: "\n -m MODE Creation mode (default a=rw)" 26//usage: "\n -m MODE Creation mode (default a=rw)"
@@ -30,7 +30,7 @@
30//usage: "\nTYPE:" 30//usage: "\nTYPE:"
31//usage: "\n b Block device" 31//usage: "\n b Block device"
32//usage: "\n c or u Character device" 32//usage: "\n c or u Character device"
33//usage: "\n p Named pipe (MAJOR and MINOR are ignored)" 33//usage: "\n p Named pipe (MAJOR MINOR must be omitted)"
34//usage: 34//usage:
35//usage:#define mknod_example_usage 35//usage:#define mknod_example_usage
36//usage: "$ mknod /dev/fd0 b 2 0\n" 36//usage: "$ mknod /dev/fd0 b 2 0\n"
@@ -47,40 +47,40 @@ static const char modes_chars[] ALIGN1 = { 'p', 'c', 'u', 'b', 0, 1, 1, 2 };
47static const mode_t modes_cubp[] = { S_IFIFO, S_IFCHR, S_IFBLK }; 47static const mode_t modes_cubp[] = { S_IFIFO, S_IFCHR, S_IFBLK };
48 48
49int mknod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 49int mknod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
50int mknod_main(int argc, char **argv) 50int mknod_main(int argc UNUSED_PARAM, char **argv)
51{ 51{
52 mode_t mode; 52 mode_t mode;
53 dev_t dev; 53 dev_t dev;
54 const char *name; 54 const char *type, *arg;
55 55
56 mode = getopt_mk_fifo_nod(argv); 56 mode = getopt_mk_fifo_nod(argv);
57 argv += optind; 57 argv += optind;
58 argc -= optind; 58 //argc -= optind;
59 59
60 if (argc >= 2) { 60 if (!argv[0] || !argv[1])
61 name = strchr(modes_chars, argv[1][0]); 61 bb_show_usage();
62 if (name != NULL) { 62 type = strchr(modes_chars, argv[1][0]);
63 mode |= modes_cubp[(int)(name[4])]; 63 if (!type)
64 bb_show_usage();
64 65
65 dev = 0; 66 mode |= modes_cubp[(int)(type[4])];
66 if (*name != 'p') {
67 argc -= 2;
68 if (argc == 2) {
69 /* Autodetect what the system supports; these macros should
70 * optimize out to two constants. */
71 dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
72 xatoul_range(argv[3], 0, minor(UINT_MAX)));
73 }
74 }
75 67
76 if (argc == 2) { 68 dev = 0;
77 name = *argv; 69 arg = argv[2];
78 if (mknod(name, mode, dev) == 0) { 70 if (*type != 'p') {
79 return EXIT_SUCCESS; 71 if (!argv[2] || !argv[3])
80 } 72 bb_show_usage();
81 bb_simple_perror_msg_and_die(name); 73 /* Autodetect what the system supports; these macros should
82 } 74 * optimize out to two constants. */
83 } 75 dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
76 xatoul_range(argv[3], 0, minor(UINT_MAX)));
77 arg = argv[4];
84 } 78 }
85 bb_show_usage(); 79 if (arg)
80 bb_show_usage();
81
82 if (mknod(argv[0], mode, dev) != 0) {
83 bb_simple_perror_msg_and_die(argv[0]);
84 }
85 return EXIT_SUCCESS;
86} 86}
diff --git a/coreutils/mv.c b/coreutils/mv.c
index 10cbc506f..aeafd1e40 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -17,7 +17,8 @@
17//config: help 17//config: help
18//config: mv is used to move or rename files or directories. 18//config: mv is used to move or rename files or directories.
19 19
20//applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP)) 20//applet:IF_MV(APPLET_NOEXEC(mv, mv, BB_DIR_BIN, BB_SUID_DROP, mv))
21/* NOEXEC despite cases when it can be a "runner" (mv LARGE_DIR OTHER_FS) */
21 22
22//kbuild:lib-$(CONFIG_MV) += mv.o 23//kbuild:lib-$(CONFIG_MV) += mv.o
23 24
diff --git a/coreutils/nice.c b/coreutils/nice.c
index d6818cf00..aa8b06cce 100644
--- a/coreutils/nice.c
+++ b/coreutils/nice.c
@@ -26,7 +26,7 @@
26#include "libbb.h" 26#include "libbb.h"
27 27
28int nice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 28int nice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29int nice_main(int argc, char **argv) 29int nice_main(int argc UNUSED_PARAM, char **argv)
30{ 30{
31 int old_priority, adjustment; 31 int old_priority, adjustment;
32 32
@@ -40,18 +40,21 @@ int nice_main(int argc, char **argv)
40 adjustment = 10; /* Set default adjustment. */ 40 adjustment = 10; /* Set default adjustment. */
41 41
42 if (argv[0][0] == '-') { 42 if (argv[0][0] == '-') {
43 if (argv[0][1] == 'n') { /* -n */ 43 char *nnn = argv[0] + 1;
44 if (argv[0][2]) { /* -nNNNN (w/o space) */ 44 if (nnn[0] == 'n') { /* -n */
45 argv[0] += 2; argv--; argc++; 45 nnn += 1;
46 if (!nnn[0]) { /* "-n NNN" */
47 nnn = *++argv;
46 } 48 }
47 } else { /* -NNN (NNN may be negative) == -n NNN */ 49 /* else: "-nNNN" (w/o space) */
48 argv[0] += 1; argv--; argc++;
49 } 50 }
50 if (argc < 4) { /* Missing priority and/or utility! */ 51 /* else: "-NNN" (NNN may be negative) - same as "-n NNN" */
52
53 if (!nnn || !argv[1]) { /* Missing priority or PROG! */
51 bb_show_usage(); 54 bb_show_usage();
52 } 55 }
53 adjustment = xatoi_range(argv[1], INT_MIN/2, INT_MAX/2); 56 adjustment = xatoi_range(nnn, INT_MIN/2, INT_MAX/2);
54 argv += 2; 57 argv++;
55 } 58 }
56 59
57 { /* Set our priority. */ 60 { /* Set our priority. */
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index df7354b7b..645a05f57 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -1378,9 +1378,13 @@ int od_main(int argc UNUSED_PARAM, char **argv)
1378 } 1378 }
1379 1379
1380#ifdef DEBUG 1380#ifdef DEBUG
1381 for (i = 0; i < G.n_specs; i++) { 1381 {
1382 printf("%d: fmt=\"%s\" width=%d\n", 1382 int i;
1383 i, spec[i].fmt_string, width_bytes[spec[i].size]); 1383 for (i = 0; i < G.n_specs; i++) {
1384 printf("%d: fmt='%s' width=%d\n",
1385 i, G.spec[i].fmt_string,
1386 width_bytes[G.spec[i].size]);
1387 }
1384 } 1388 }
1385#endif 1389#endif
1386 1390
diff --git a/coreutils/stat.c b/coreutils/stat.c
index 177ced2f9..41f6d103c 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -758,10 +758,13 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
758 IF_FEATURE_STAT_FORMAT(char *format = NULL;) 758 IF_FEATURE_STAT_FORMAT(char *format = NULL;)
759 int i; 759 int i;
760 int ok; 760 int ok;
761 unsigned opts;
762 statfunc_ptr statfunc = do_stat; 761 statfunc_ptr statfunc = do_stat;
762#if ENABLE_FEATURE_STAT_FILESYSTEM || ENABLE_SELINUX
763 unsigned opts;
763 764
764 opts = getopt32(argv, "^" 765 opts =
766#endif
767 getopt32(argv, "^"
765 "tL" 768 "tL"
766 IF_FEATURE_STAT_FILESYSTEM("f") 769 IF_FEATURE_STAT_FILESYSTEM("f")
767 IF_SELINUX("Z") 770 IF_SELINUX("Z")
diff --git a/coreutils/uname.c b/coreutils/uname.c
index 57039b1bf..765809658 100644
--- a/coreutils/uname.c
+++ b/coreutils/uname.c
@@ -127,11 +127,9 @@ int uname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
127{ 127{
128 uname_info_t uname_info; 128 uname_info_t uname_info;
129 IF_UNAME(const char *unknown_str = "unknown";) 129 IF_UNAME(const char *unknown_str = "unknown";)
130 unsigned toprint;
131
132 toprint = (1 << 4); /* "arch" = "uname -m" */
133
134#if ENABLE_UNAME 130#if ENABLE_UNAME
131 unsigned toprint = (1 << 4); /* "arch" = "uname -m" */
132
135 if (!ENABLE_BB_ARCH || applet_name[0] == 'u') { 133 if (!ENABLE_BB_ARCH || applet_name[0] == 'u') {
136# if ENABLE_LONG_OPTS 134# if ENABLE_LONG_OPTS
137 static const char uname_longopts[] ALIGN1 = 135 static const char uname_longopts[] ALIGN1 =