aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/dd.c15
-rw-r--r--coreutils/du.c2
-rw-r--r--coreutils/expr.c2
-rw-r--r--coreutils/factor.c4
-rw-r--r--coreutils/ls.c12
-rw-r--r--coreutils/od_bloaty.c7
-rw-r--r--coreutils/shred.c10
-rw-r--r--coreutils/stat.c10
-rw-r--r--coreutils/sum.c4
-rw-r--r--coreutils/timeout.c53
-rw-r--r--coreutils/yes.c4
11 files changed, 112 insertions, 11 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index b5f3cbec5..3054ec6ea 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -91,6 +91,9 @@
91//usage: "\n status=none Suppress all output" 91//usage: "\n status=none Suppress all output"
92//usage: ) 92//usage: )
93//usage: "\n" 93//usage: "\n"
94//usage: IF_PLATFORM_MINGW32(
95//usage: "\nif=/dev/zero and if=/dev/urandom are supported"
96//usage: )
94//usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G" 97//usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G"
95//usage: 98//usage:
96//usage:#define dd_example_usage 99//usage:#define dd_example_usage
@@ -367,11 +370,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
367#if ENABLE_FEATURE_DD_IBS_OBS 370#if ENABLE_FEATURE_DD_IBS_OBS
368 if (what == OP_ibs) { 371 if (what == OP_ibs) {
369 /* Must fit into positive ssize_t */ 372 /* Must fit into positive ssize_t */
370 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 373 ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes);
371 /*continue;*/ 374 /*continue;*/
372 } 375 }
373 if (what == OP_obs) { 376 if (what == OP_obs) {
374 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 377 obs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes);
375 /*continue;*/ 378 /*continue;*/
376 } 379 }
377 if (what == OP_conv) { 380 if (what == OP_conv) {
@@ -388,7 +391,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
388 } 391 }
389#endif 392#endif
390 if (what == OP_bs) { 393 if (what == OP_bs) {
391 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 394 ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes);
392 obs = ibs; 395 obs = ibs;
393 /*continue;*/ 396 /*continue;*/
394 } 397 }
@@ -444,7 +447,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
444#endif 447#endif
445 448
446 if (infile) { 449 if (infile) {
450#if !ENABLE_PLATFORM_MINGW32
447 xmove_fd(xopen(infile, O_RDONLY), ifd); 451 xmove_fd(xopen(infile, O_RDONLY), ifd);
452#else
453 xmove_fd(mingw_xopen(infile, O_RDONLY), ifd);
454 update_dev_fd(get_dev_type(infile), ifd);
455#endif
448 } else { 456 } else {
449 infile = bb_msg_standard_input; 457 infile = bb_msg_standard_input;
450 } 458 }
@@ -500,6 +508,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
500 508
501 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { 509 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
502 ssize_t n; 510 ssize_t n;
511
503#if ENABLE_FEATURE_DD_IBS_OBS 512#if ENABLE_FEATURE_DD_IBS_OBS
504 if (G.flags & FLAG_FULLBLOCK) 513 if (G.flags & FLAG_FULLBLOCK)
505 n = full_read(ifd, ibuf, ibs); 514 n = full_read(ifd, ibuf, ibs);
diff --git a/coreutils/du.c b/coreutils/du.c
index d14d9e4ea..4fd09a8ee 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -131,7 +131,7 @@ static void print(unsigned long long size, const char *filename)
131 size++; 131 size++;
132 size >>= 1; 132 size >>= 1;
133 } 133 }
134 printf("%llu\t%s\n", size, filename); 134 printf("%"LL_FMT"u\t%s\n", size, filename);
135#endif 135#endif
136} 136}
137 137
diff --git a/coreutils/expr.c b/coreutils/expr.c
index 1bdfba004..900248103 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -84,7 +84,7 @@
84#if ENABLE_EXPR_MATH_SUPPORT_64 84#if ENABLE_EXPR_MATH_SUPPORT_64
85typedef int64_t arith_t; 85typedef int64_t arith_t;
86 86
87#define PF_REZ "ll" 87#define PF_REZ LL_FMT
88#define PF_REZ_TYPE (long long) 88#define PF_REZ_TYPE (long long)
89#define STRTOL(s, e, b) strtoll(s, e, b) 89#define STRTOL(s, e, b) strtoll(s, e, b)
90#else 90#else
diff --git a/coreutils/factor.c b/coreutils/factor.c
index 1f24784fd..47fe179dc 100644
--- a/coreutils/factor.c
+++ b/coreutils/factor.c
@@ -161,7 +161,7 @@ static NOINLINE void factorize(wide_t N)
161 } 161 }
162 end: 162 end:
163 if (N > 1) 163 if (N > 1)
164 printf(" %llu", N); 164 printf(" %"LL_FMT"u", N);
165 bb_putchar('\n'); 165 bb_putchar('\n');
166} 166}
167 167
@@ -175,7 +175,7 @@ static void factorize_numstr(const char *numstr)
175 N = bb_strtoull(numstr, NULL, 10); 175 N = bb_strtoull(numstr, NULL, 10);
176 if (errno) 176 if (errno)
177 bb_show_usage(); 177 bb_show_usage();
178 printf("%llu:", N); 178 printf("%"LL_FMT"u:", N);
179 factorize(N); 179 factorize(N);
180} 180}
181 181
diff --git a/coreutils/ls.c b/coreutils/ls.c
index e5375a61a..3eff5a949 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -492,12 +492,18 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
492 /* Do readlink early, so that if it fails, error message 492 /* Do readlink early, so that if it fails, error message
493 * does not appear *inside* the "ls -l" line */ 493 * does not appear *inside* the "ls -l" line */
494 lpath = NULL; 494 lpath = NULL;
495#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2
495 if (opt & OPT_l) 496 if (opt & OPT_l)
496 if (S_ISLNK(dn->dn_mode)) 497 if (S_ISLNK(dn->dn_mode))
497 lpath = xmalloc_readlink_or_warn(dn->fullname); 498 lpath = xmalloc_readlink_or_warn(dn->fullname);
499#endif
498 500
499 if (opt & OPT_i) /* show inode# */ 501 if (opt & OPT_i) /* show inode# */
500 column += printf("%7llu ", (long long) dn->dn_ino); 502#if !ENABLE_FEATURE_EXTRA_FILE_DATA
503 column += printf("%7"LL_FMT"u ", (long long) dn->dn_ino);
504#else
505 column += printf("%19"LL_FMT"u ", (long long) dn->dn_ino);
506#endif
501//TODO: -h should affect -s too: 507//TODO: -h should affect -s too:
502 if (opt & OPT_s) /* show allocated blocks */ 508 if (opt & OPT_s) /* show allocated blocks */
503 column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); 509 column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
@@ -651,7 +657,11 @@ static void display_files(struct dnode **dn, unsigned nfiles)
651 } 657 }
652 column_width += 2 658 column_width += 2
653 + ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */ 659 + ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */
660#if !ENABLE_FEATURE_EXTRA_FILE_DATA
654 + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ 661 + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */
662#else
663 + ((option_mask32 & OPT_i) ? 20 : 0) /* inode# width */
664#endif
655 + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */ 665 + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */
656 ; 666 ;
657 ncols = (unsigned)G_terminal_width / column_width; 667 ncols = (unsigned)G_terminal_width / column_width;
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 4cae0c529..75e14ef7d 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -101,6 +101,13 @@ typedef long long llong;
101# define LDBL_DIG DBL_DIG 101# define LDBL_DIG DBL_DIG
102#endif 102#endif
103 103
104#if ENABLE_PLATFORM_MINGW32
105/* symbol conflict */
106#define CHAR SIZE_CHAR
107#define SHORT SIZE_SHORT
108#define LONG SIZE_LONG
109#define INT SIZE_INT
110#endif
104enum size_spec { 111enum size_spec {
105 NO_SIZE, 112 NO_SIZE,
106 CHAR, 113 CHAR,
diff --git a/coreutils/shred.c b/coreutils/shred.c
index 8f3d9c5c9..86d4b66b4 100644
--- a/coreutils/shred.c
+++ b/coreutils/shred.c
@@ -38,6 +38,10 @@
38 38
39#include "libbb.h" 39#include "libbb.h"
40 40
41#if ENABLE_PLATFORM_MINGW32
42#define xopen mingw_xopen
43#endif
44
41int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 45int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
42int shred_main(int argc UNUSED_PARAM, char **argv) 46int shred_main(int argc UNUSED_PARAM, char **argv)
43{ 47{
@@ -96,8 +100,14 @@ int shred_main(int argc UNUSED_PARAM, char **argv)
96 } 100 }
97 if (opt & OPT_u) { 101 if (opt & OPT_u) {
98 ftruncate(fd, 0); 102 ftruncate(fd, 0);
103#if ENABLE_PLATFORM_MINGW32
104 xclose(fd);
105#endif
99 xunlink(fname); 106 xunlink(fname);
100 } 107 }
108#if ENABLE_PLATFORM_MINGW32
109 else
110#endif
101 xclose(fd); 111 xclose(fd);
102 } 112 }
103 } 113 }
diff --git a/coreutils/stat.c b/coreutils/stat.c
index b6ab5205b..d9287b34e 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -31,7 +31,6 @@
31//config: bool "Enable display of filesystem status (-f)" 31//config: bool "Enable display of filesystem status (-f)"
32//config: default y 32//config: default y
33//config: depends on STAT 33//config: depends on STAT
34//config: select PLATFORM_LINUX # statfs()
35//config: help 34//config: help
36//config: Without this, stat will not support the '-f' option to display 35//config: Without this, stat will not support the '-f' option to display
37//config: information about filesystem status. 36//config: information about filesystem status.
@@ -195,6 +194,7 @@ FS_TYPE(0x012FF7B4, "xenix") \
195FS_TYPE(0x012FF7B5, "sysv4") \ 194FS_TYPE(0x012FF7B5, "sysv4") \
196FS_TYPE(0x012FF7B6, "sysv2") \ 195FS_TYPE(0x012FF7B6, "sysv2") \
197FS_TYPE(0x012FF7B7, "coh") \ 196FS_TYPE(0x012FF7B7, "coh") \
197IF_PLATFORM_MINGW32(FS_TYPE(0x15013346, "udf")) \
198FS_TYPE(0x00011954, "ufs") \ 198FS_TYPE(0x00011954, "ufs") \
199FS_TYPE(0x012FD16D, "xia") \ 199FS_TYPE(0x012FD16D, "xia") \
200FS_TYPE(0x5346544e, "ntfs") \ 200FS_TYPE(0x5346544e, "ntfs") \
@@ -322,6 +322,7 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
322 printfs(pformat, filename); 322 printfs(pformat, filename);
323 } else if (m == 'N') { 323 } else if (m == 'N') {
324 strcatc(pformat, 's'); 324 strcatc(pformat, 's');
325#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2
325 if (S_ISLNK(statbuf->st_mode)) { 326 if (S_ISLNK(statbuf->st_mode)) {
326 char *linkname = xmalloc_readlink_or_warn(filename); 327 char *linkname = xmalloc_readlink_or_warn(filename);
327 if (linkname == NULL) 328 if (linkname == NULL)
@@ -331,6 +332,9 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
331 } else { 332 } else {
332 printf(pformat, filename); 333 printf(pformat, filename);
333 } 334 }
335#else
336 printf(pformat, filename);
337#endif
334 } else if (m == 'd') { 338 } else if (m == 'd') {
335 strcat(pformat, "llu"); 339 strcat(pformat, "llu");
336 printf(pformat, (unsigned long long) statbuf->st_dev); 340 printf(pformat, (unsigned long long) statbuf->st_dev);
@@ -713,6 +717,7 @@ static bool do_stat(const char *filename, const char *format)
713 gw_ent = getgrgid(statbuf.st_gid); 717 gw_ent = getgrgid(statbuf.st_gid);
714 pw_ent = getpwuid(statbuf.st_uid); 718 pw_ent = getpwuid(statbuf.st_uid);
715 719
720#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2
716 if (S_ISLNK(statbuf.st_mode)) 721 if (S_ISLNK(statbuf.st_mode))
717 linkname = xmalloc_readlink_or_warn(filename); 722 linkname = xmalloc_readlink_or_warn(filename);
718 if (linkname) { 723 if (linkname) {
@@ -721,6 +726,9 @@ static bool do_stat(const char *filename, const char *format)
721 } else { 726 } else {
722 printf(" File: '%s'\n", filename); 727 printf(" File: '%s'\n", filename);
723 } 728 }
729#else
730 printf(" File: '%s'\n", filename);
731#endif
724 732
725 printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" 733 printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n"
726 "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", 734 "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu",
diff --git a/coreutils/sum.c b/coreutils/sum.c
index 16ec44540..a15d1932d 100644
--- a/coreutils/sum.c
+++ b/coreutils/sum.c
@@ -82,9 +82,9 @@ static unsigned sum_file(const char *file, unsigned type)
82 if (type >= SUM_SYSV) { 82 if (type >= SUM_SYSV) {
83 r = (s & 0xffff) + ((s & 0xffffffff) >> 16); 83 r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
84 s = (r & 0xffff) + (r >> 16); 84 s = (r & 0xffff) + (r >> 16);
85 printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file); 85 printf("%u %"LL_FMT"u %s\n", s, (total_bytes + 511) / 512, file);
86 } else 86 } else
87 printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file); 87 printf("%05u %5"LL_FMT"u %s\n", s, (total_bytes + 1023) / 1024, file);
88 return 1; 88 return 1;
89#undef buf 89#undef buf
90} 90}
diff --git a/coreutils/timeout.c b/coreutils/timeout.c
index 8b7bc2eaa..258cd276f 100644
--- a/coreutils/timeout.c
+++ b/coreutils/timeout.c
@@ -46,11 +46,27 @@
46 46
47#include "libbb.h" 47#include "libbb.h"
48 48
49#if ENABLE_PLATFORM_MINGW32
50HANDLE child = INVALID_HANDLE_VALUE;
51
52static void kill_child(void)
53{
54 if (child != INVALID_HANDLE_VALUE) {
55 kill_SIGTERM_by_handle(child, 128+SIGTERM);
56 }
57}
58#endif
59
49int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 60int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
50int timeout_main(int argc UNUSED_PARAM, char **argv) 61int timeout_main(int argc UNUSED_PARAM, char **argv)
51{ 62{
52 int signo; 63 int signo;
64#if !ENABLE_PLATFORM_MINGW32
53 int status; 65 int status;
66#else
67 intptr_t ret;
68 DWORD status = EXIT_SUCCESS;
69#endif
54 int parent = 0; 70 int parent = 0;
55 int timeout; 71 int timeout;
56 pid_t pid; 72 pid_t pid;
@@ -59,6 +75,10 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
59#endif 75#endif
60 const char *opt_s = "TERM"; 76 const char *opt_s = "TERM";
61 77
78#if ENABLE_PLATFORM_MINGW32
79 xfunc_error_retval = 125;
80#endif
81
62 /* -p option is not documented, it is needed to support NOMMU. */ 82 /* -p option is not documented, it is needed to support NOMMU. */
63 83
64 /* -t SECONDS; -p PARENT_PID */ 84 /* -t SECONDS; -p PARENT_PID */
@@ -67,7 +87,11 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
67 /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ 87 /*argv += optind; - no, wait for bb_daemonize_or_rexec! */
68 88
69 signo = get_signum(opt_s); 89 signo = get_signum(opt_s);
90#if !ENABLE_PLATFORM_MINGW32
70 if (signo < 0) 91 if (signo < 0)
92#else
93 if (signo != SIGTERM && signo != SIGKILL && signo != 0)
94#endif
71 bb_error_msg_and_die("unknown signal '%s'", opt_s); 95 bb_error_msg_and_die("unknown signal '%s'", opt_s);
72 96
73 if (!argv[optind]) 97 if (!argv[optind])
@@ -76,6 +100,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
76 if (!argv[optind]) /* no PROG? */ 100 if (!argv[optind]) /* no PROG? */
77 bb_show_usage(); 101 bb_show_usage();
78 102
103#if !ENABLE_PLATFORM_MINGW32
79 /* We want to create a grandchild which will watch 104 /* We want to create a grandchild which will watch
80 * and kill the grandparent. Other methods: 105 * and kill the grandparent. Other methods:
81 * making parent watch child disrupts parent<->child link 106 * making parent watch child disrupts parent<->child link
@@ -129,4 +154,32 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
129 argv[1] = sv2; 154 argv[1] = sv2;
130#endif 155#endif
131 BB_EXECVP_or_die(argv); 156 BB_EXECVP_or_die(argv);
157#else /* ENABLE_PLATFORM_MINGW32 */
158 if ((ret=mingw_spawn_proc((const char **)argv)) == -1) {
159 xfunc_error_retval = errno == EACCES ? 126 : 127;
160 bb_perror_msg_and_die("can't execute '%s'", argv[0]);
161 }
162
163 child = (HANDLE)ret;
164 atexit(kill_child);
165 while (1) {
166 sleep(1);
167 if (signo && --timeout <= 0) {
168 status = signo == SIGKILL ? 137 : 124;
169 break;
170 }
171 if (WaitForSingleObject(child, 0) == WAIT_OBJECT_0) {
172 /* process is gone */
173 GetExitCodeProcess(child, &status);
174 goto finish;
175 }
176 }
177
178 pid = (pid_t)GetProcessId(child);
179 kill(pid, signo);
180 finish:
181 CloseHandle(child);
182 child = INVALID_HANDLE_VALUE;
183 return status;
184#endif
132} 185}
diff --git a/coreutils/yes.c b/coreutils/yes.c
index 9a435a761..a51b1ad8e 100644
--- a/coreutils/yes.c
+++ b/coreutils/yes.c
@@ -41,6 +41,10 @@ int yes_main(int argc UNUSED_PARAM, char **argv)
41 ++argv; 41 ++argv;
42 42
43 do { 43 do {
44#if ENABLE_PLATFORM_MINGW32
45 if (ferror(stdout) != 0)
46 break;
47#endif
44 pp = argv; 48 pp = argv;
45 while (1) { 49 while (1) {
46 fputs(*pp, stdout); 50 fputs(*pp, stdout);