diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/date.c | 25 | ||||
-rw-r--r-- | coreutils/dd.c | 61 | ||||
-rw-r--r-- | coreutils/du.c | 2 | ||||
-rw-r--r-- | coreutils/expr.c | 2 | ||||
-rw-r--r-- | coreutils/factor.c | 4 | ||||
-rw-r--r-- | coreutils/ls.c | 48 | ||||
-rw-r--r-- | coreutils/nproc.c | 18 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 7 | ||||
-rw-r--r-- | coreutils/printf.c | 68 | ||||
-rw-r--r-- | coreutils/shred.c | 10 | ||||
-rw-r--r-- | coreutils/split.c | 8 | ||||
-rw-r--r-- | coreutils/stat.c | 5 | ||||
-rw-r--r-- | coreutils/sum.c | 4 | ||||
-rw-r--r-- | coreutils/timeout.c | 76 | ||||
-rw-r--r-- | coreutils/yes.c | 5 |
15 files changed, 324 insertions, 19 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index abcc37c33..4e62a6fb0 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -97,7 +97,9 @@ | |||
97 | //usage:#define date_full_usage "\n\n" | 97 | //usage:#define date_full_usage "\n\n" |
98 | //usage: "Display time (using +FMT), or set time\n" | 98 | //usage: "Display time (using +FMT), or set time\n" |
99 | //usage: "\n -u Work in UTC (don't convert to local time)" | 99 | //usage: "\n -u Work in UTC (don't convert to local time)" |
100 | //usage: IF_NOT_PLATFORM_MINGW32( | ||
100 | //usage: "\n [-s] TIME Set time to TIME" | 101 | //usage: "\n [-s] TIME Set time to TIME" |
102 | //usage: ) | ||
101 | //usage: "\n -d TIME Display TIME, not 'now'" | 103 | //usage: "\n -d TIME Display TIME, not 'now'" |
102 | //usage: IF_FEATURE_DATE_ISOFMT( | 104 | //usage: IF_FEATURE_DATE_ISOFMT( |
103 | //usage: "\n -D FMT FMT (strptime format) for -s/-d TIME conversion" | 105 | //usage: "\n -D FMT FMT (strptime format) for -s/-d TIME conversion" |
@@ -132,19 +134,30 @@ | |||
132 | 134 | ||
133 | enum { | 135 | enum { |
134 | OPT_RFC2822 = (1 << 0), /* R */ | 136 | OPT_RFC2822 = (1 << 0), /* R */ |
137 | #if !ENABLE_PLATFORM_MINGW32 | ||
135 | OPT_SET = (1 << 1), /* s */ | 138 | OPT_SET = (1 << 1), /* s */ |
136 | OPT_UTC = (1 << 2), /* u */ | 139 | OPT_UTC = (1 << 2), /* u */ |
137 | OPT_DATE = (1 << 3), /* d */ | 140 | OPT_DATE = (1 << 3), /* d */ |
138 | OPT_REFERENCE = (1 << 4), /* r */ | 141 | OPT_REFERENCE = (1 << 4), /* r */ |
139 | OPT_ISO8601 = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */ | 142 | OPT_ISO8601 = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */ |
140 | OPT_STR2DT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ | 143 | OPT_STR2DT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ |
144 | #else | ||
145 | OPT_SET = (0), /* s */ | ||
146 | OPT_UTC = (1 << 1), /* u */ | ||
147 | OPT_DATE = (1 << 2), /* d */ | ||
148 | OPT_REFERENCE = (1 << 3), /* r */ | ||
149 | OPT_ISO8601 = (1 << 4) * ENABLE_FEATURE_DATE_ISOFMT, /* I */ | ||
150 | OPT_STR2DT = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ | ||
151 | #endif | ||
141 | }; | 152 | }; |
142 | 153 | ||
143 | #if ENABLE_LONG_OPTS | 154 | #if ENABLE_LONG_OPTS |
144 | static const char date_longopts[] ALIGN1 = | 155 | static const char date_longopts[] ALIGN1 = |
145 | "rfc-822\0" No_argument "R" | 156 | "rfc-822\0" No_argument "R" |
146 | "rfc-2822\0" No_argument "R" | 157 | "rfc-2822\0" No_argument "R" |
158 | #if !ENABLE_PLATFORM_MINGW32 | ||
147 | "set\0" Required_argument "s" | 159 | "set\0" Required_argument "s" |
160 | #endif | ||
148 | "utc\0" No_argument "u" | 161 | "utc\0" No_argument "u" |
149 | /* "universal\0" No_argument "u" */ | 162 | /* "universal\0" No_argument "u" */ |
150 | "date\0" Required_argument "d" | 163 | "date\0" Required_argument "d" |
@@ -174,13 +187,25 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
174 | char *isofmt_arg = NULL; | 187 | char *isofmt_arg = NULL; |
175 | 188 | ||
176 | opt = getopt32long(argv, "^" | 189 | opt = getopt32long(argv, "^" |
190 | #if !ENABLE_PLATFORM_MINGW32 | ||
177 | "Rs:ud:r:" | 191 | "Rs:ud:r:" |
192 | #else | ||
193 | "Rud:r:" | ||
194 | #endif | ||
178 | IF_FEATURE_DATE_ISOFMT("I::D:") | 195 | IF_FEATURE_DATE_ISOFMT("I::D:") |
196 | #if !ENABLE_PLATFORM_MINGW32 | ||
179 | "\0" | 197 | "\0" |
180 | "d--s:s--d" | 198 | "d--s:s--d" |
181 | IF_FEATURE_DATE_ISOFMT(":R--I:I--R"), | 199 | IF_FEATURE_DATE_ISOFMT(":R--I:I--R"), |
200 | #else | ||
201 | IF_FEATURE_DATE_ISOFMT("\0R--I:I--R"), | ||
202 | #endif | ||
182 | date_longopts, | 203 | date_longopts, |
204 | #if !ENABLE_PLATFORM_MINGW32 | ||
183 | &date_str, &date_str, &filename | 205 | &date_str, &date_str, &filename |
206 | #else | ||
207 | &date_str, &filename | ||
208 | #endif | ||
184 | IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt) | 209 | IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt) |
185 | ); | 210 | ); |
186 | argv += optind; | 211 | argv += optind; |
diff --git a/coreutils/dd.c b/coreutils/dd.c index 3e034eb1e..0989c9c2c 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -59,8 +59,13 @@ | |||
59 | //usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]" | 59 | //usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]" |
60 | //usage: IF_FEATURE_DD_IBS_OBS("\n" | 60 | //usage: IF_FEATURE_DD_IBS_OBS("\n" |
61 | //usage: " [conv=notrunc|noerror|sync|fsync]\n" | 61 | //usage: " [conv=notrunc|noerror|sync|fsync]\n" |
62 | //usage: IF_NOT_PLATFORM_MINGW32( | ||
62 | //usage: " [iflag=skip_bytes|count_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]" | 63 | //usage: " [iflag=skip_bytes|count_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]" |
63 | //usage: ) | 64 | //usage: ) |
65 | //usage: IF_PLATFORM_MINGW32( | ||
66 | //usage: " [iflag=skip_bytes|count_bytes|fullblock] [oflag=seek_bytes|append]" | ||
67 | //usage: ) | ||
68 | //usage: ) | ||
64 | //usage:#define dd_full_usage "\n\n" | 69 | //usage:#define dd_full_usage "\n\n" |
65 | //usage: "Copy a file with converting and formatting\n" | 70 | //usage: "Copy a file with converting and formatting\n" |
66 | //usage: "\n if=FILE Read from FILE instead of stdin" | 71 | //usage: "\n if=FILE Read from FILE instead of stdin" |
@@ -84,8 +89,10 @@ | |||
84 | //usage: "\n iflag=skip_bytes skip=N is in bytes" | 89 | //usage: "\n iflag=skip_bytes skip=N is in bytes" |
85 | //usage: "\n iflag=count_bytes count=N is in bytes" | 90 | //usage: "\n iflag=count_bytes count=N is in bytes" |
86 | //usage: "\n oflag=seek_bytes seek=N is in bytes" | 91 | //usage: "\n oflag=seek_bytes seek=N is in bytes" |
92 | //usage: IF_NOT_PLATFORM_MINGW32( | ||
87 | //usage: "\n iflag=direct O_DIRECT input" | 93 | //usage: "\n iflag=direct O_DIRECT input" |
88 | //usage: "\n oflag=direct O_DIRECT output" | 94 | //usage: "\n oflag=direct O_DIRECT output" |
95 | //usage: ) | ||
89 | //usage: "\n iflag=fullblock Read full blocks" | 96 | //usage: "\n iflag=fullblock Read full blocks" |
90 | //usage: "\n oflag=append Open output in append mode" | 97 | //usage: "\n oflag=append Open output in append mode" |
91 | //usage: ) | 98 | //usage: ) |
@@ -94,6 +101,9 @@ | |||
94 | //usage: "\n status=none Suppress all output" | 101 | //usage: "\n status=none Suppress all output" |
95 | //usage: ) | 102 | //usage: ) |
96 | //usage: "\n" | 103 | //usage: "\n" |
104 | //usage: IF_PLATFORM_MINGW32( | ||
105 | //usage: "\nif=/dev/zero and if=/dev/urandom are supported" | ||
106 | //usage: ) | ||
97 | //usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G" | 107 | //usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G" |
98 | //usage: | 108 | //usage: |
99 | //usage:#define dd_example_usage | 109 | //usage:#define dd_example_usage |
@@ -104,6 +114,10 @@ | |||
104 | #include "libbb.h" | 114 | #include "libbb.h" |
105 | #include "common_bufsiz.h" | 115 | #include "common_bufsiz.h" |
106 | 116 | ||
117 | #if ENABLE_PLATFORM_MINGW32 | ||
118 | # undef O_DIRECT | ||
119 | #endif | ||
120 | |||
107 | /* This is a NOEXEC applet. Be very careful! */ | 121 | /* This is a NOEXEC applet. Be very careful! */ |
108 | 122 | ||
109 | 123 | ||
@@ -141,13 +155,13 @@ enum { | |||
141 | FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, | 155 | FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, |
142 | FLAG_COUNT_BYTES = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, | 156 | FLAG_COUNT_BYTES = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, |
143 | FLAG_FULLBLOCK = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS, | 157 | FLAG_FULLBLOCK = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS, |
144 | FLAG_IDIRECT = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS, | 158 | FLAG_IDIRECT = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS * ENABLE_PLATFORM_POSIX, |
145 | /* end of input flags */ | 159 | /* end of input flags */ |
146 | /* start of output flags */ | 160 | /* start of output flags */ |
147 | FLAG_OFLAG_SHIFT = 9, | 161 | FLAG_OFLAG_SHIFT = 9, |
148 | FLAG_SEEK_BYTES = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS, | 162 | FLAG_SEEK_BYTES = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS, |
149 | FLAG_APPEND = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS, | 163 | FLAG_APPEND = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS, |
150 | FLAG_ODIRECT = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS, | 164 | FLAG_ODIRECT = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS * ENABLE_PLATFORM_POSIX, |
151 | /* end of output flags */ | 165 | /* end of output flags */ |
152 | FLAG_TWOBUFS = (1 << 12) * ENABLE_FEATURE_DD_IBS_OBS, | 166 | FLAG_TWOBUFS = (1 << 12) * ENABLE_FEATURE_DD_IBS_OBS, |
153 | FLAG_COUNT = 1 << 13, | 167 | FLAG_COUNT = 1 << 13, |
@@ -220,7 +234,9 @@ static ssize_t dd_read(void *ibuf, size_t ibs) | |||
220 | ssize_t n; | 234 | ssize_t n; |
221 | 235 | ||
222 | #if ENABLE_FEATURE_DD_IBS_OBS | 236 | #if ENABLE_FEATURE_DD_IBS_OBS |
237 | # if !ENABLE_PLATFORM_MINGW32 | ||
223 | read_again: | 238 | read_again: |
239 | # endif | ||
224 | if (G.flags & FLAG_FULLBLOCK) | 240 | if (G.flags & FLAG_FULLBLOCK) |
225 | n = full_read(ifd, ibuf, ibs); | 241 | n = full_read(ifd, ibuf, ibs); |
226 | else | 242 | else |
@@ -240,7 +256,9 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs, | |||
240 | { | 256 | { |
241 | ssize_t n; | 257 | ssize_t n; |
242 | 258 | ||
259 | #if !ENABLE_PLATFORM_MINGW32 | ||
243 | IF_FEATURE_DD_IBS_OBS(write_again:) | 260 | IF_FEATURE_DD_IBS_OBS(write_again:) |
261 | #endif | ||
244 | n = full_write(ofd, buf, len); | 262 | n = full_write(ofd, buf, len); |
245 | #if ENABLE_FEATURE_DD_IBS_OBS | 263 | #if ENABLE_FEATURE_DD_IBS_OBS |
246 | # ifdef O_DIRECT | 264 | # ifdef O_DIRECT |
@@ -307,9 +325,11 @@ static int parse_comma_flags(char *val, const char *words, const char *error_in) | |||
307 | 325 | ||
308 | static void *alloc_buf(size_t size) | 326 | static void *alloc_buf(size_t size) |
309 | { | 327 | { |
328 | #if !ENABLE_PLATFORM_MINGW32 | ||
310 | /* Important for "{i,o}flag=direct" - buffers must be page aligned */ | 329 | /* Important for "{i,o}flag=direct" - buffers must be page aligned */ |
311 | if (size >= bb_getpagesize()) | 330 | if (size >= bb_getpagesize()) |
312 | return xmmap_anon(size); | 331 | return xmmap_anon(size); |
332 | #endif | ||
313 | return xmalloc(size); | 333 | return xmalloc(size); |
314 | } | 334 | } |
315 | 335 | ||
@@ -326,9 +346,9 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
326 | static const char conv_words[] ALIGN1 = | 346 | static const char conv_words[] ALIGN1 = |
327 | "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; | 347 | "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; |
328 | static const char iflag_words[] ALIGN1 = | 348 | static const char iflag_words[] ALIGN1 = |
329 | "skip_bytes\0""count_bytes\0""fullblock\0""direct\0"; | 349 | "skip_bytes\0""count_bytes\0""fullblock\0"IF_PLATFORM_POSIX("direct\0"); |
330 | static const char oflag_words[] ALIGN1 = | 350 | static const char oflag_words[] ALIGN1 = |
331 | "seek_bytes\0append\0""direct\0"; | 351 | "seek_bytes\0append\0"IF_PLATFORM_POSIX("direct\0"); |
332 | #endif | 352 | #endif |
333 | #if ENABLE_FEATURE_DD_STATUS | 353 | #if ENABLE_FEATURE_DD_STATUS |
334 | static const char status_words[] ALIGN1 = | 354 | static const char status_words[] ALIGN1 = |
@@ -429,11 +449,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
429 | #if ENABLE_FEATURE_DD_IBS_OBS | 449 | #if ENABLE_FEATURE_DD_IBS_OBS |
430 | if (what == OP_ibs) { | 450 | if (what == OP_ibs) { |
431 | /* Must fit into positive ssize_t */ | 451 | /* Must fit into positive ssize_t */ |
432 | ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); | 452 | ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes); |
433 | /*continue;*/ | 453 | /*continue;*/ |
434 | } | 454 | } |
435 | if (what == OP_obs) { | 455 | if (what == OP_obs) { |
436 | obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); | 456 | obs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes); |
437 | /*continue;*/ | 457 | /*continue;*/ |
438 | } | 458 | } |
439 | if (what == OP_conv) { | 459 | if (what == OP_conv) { |
@@ -450,7 +470,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
450 | } | 470 | } |
451 | #endif | 471 | #endif |
452 | if (what == OP_bs) { | 472 | if (what == OP_bs) { |
453 | ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); | 473 | ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes); |
454 | obs = ibs; | 474 | obs = ibs; |
455 | /*continue;*/ | 475 | /*continue;*/ |
456 | } | 476 | } |
@@ -515,7 +535,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
515 | # endif | 535 | # endif |
516 | } | 536 | } |
517 | #endif | 537 | #endif |
518 | xmove_fd(xopen(infile, iflag), ifd); | 538 | xmove_fd(MINGW_SPECIAL(xopen)(infile, iflag), ifd); |
539 | #if ENABLE_PLATFORM_MINGW32 | ||
540 | update_special_fd(get_dev_type(infile), ifd); | ||
541 | #endif | ||
519 | } else { | 542 | } else { |
520 | infile = bb_msg_standard_input; | 543 | infile = bb_msg_standard_input; |
521 | } | 544 | } |
@@ -537,6 +560,27 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
537 | #endif | 560 | #endif |
538 | xmove_fd(xopen(outfile, oflag), ofd); | 561 | xmove_fd(xopen(outfile, oflag), ofd); |
539 | 562 | ||
563 | #if ENABLE_PLATFORM_MINGW32 | ||
564 | { | ||
565 | off_t len = (off_t)seek * ((G.flags & FLAG_SEEK_BYTES) ? 1 : obs); | ||
566 | struct stat st; | ||
567 | int ret = fstat(ofd, &st); | ||
568 | |||
569 | if (ret == 0 && !(G.flags & FLAG_APPEND) && len > st.st_size) | ||
570 | make_sparse(ofd, st.st_size, len); | ||
571 | |||
572 | if (seek && !(G.flags & FLAG_NOTRUNC)) { | ||
573 | if (ftruncate(ofd, len) < 0) { | ||
574 | if (ret < 0 | ||
575 | || S_ISREG(st.st_mode) | ||
576 | || S_ISDIR(st.st_mode) | ||
577 | ) { | ||
578 | goto die_outfile; | ||
579 | } | ||
580 | } | ||
581 | } | ||
582 | } | ||
583 | #else | ||
540 | if (seek && !(G.flags & FLAG_NOTRUNC)) { | 584 | if (seek && !(G.flags & FLAG_NOTRUNC)) { |
541 | size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs; | 585 | size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs; |
542 | if (ftruncate(ofd, seek * blocksz) < 0) { | 586 | if (ftruncate(ofd, seek * blocksz) < 0) { |
@@ -550,6 +594,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
550 | } | 594 | } |
551 | } | 595 | } |
552 | } | 596 | } |
597 | #endif | ||
553 | } else { | 598 | } else { |
554 | outfile = bb_msg_standard_output; | 599 | outfile = bb_msg_standard_output; |
555 | } | 600 | } |
diff --git a/coreutils/du.c b/coreutils/du.c index 832dd7594..092647468 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -137,7 +137,7 @@ static void print(unsigned long long size, const char *filename) | |||
137 | size >>= 10; | 137 | size >>= 10; |
138 | } | 138 | } |
139 | } | 139 | } |
140 | printf("%llu\t%s\n", size, filename); | 140 | printf("%"LL_FMT"u\t%s\n", size, filename); |
141 | #endif | 141 | #endif |
142 | } | 142 | } |
143 | 143 | ||
diff --git a/coreutils/expr.c b/coreutils/expr.c index 760b081f9..b896acd44 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 |
85 | typedef int64_t arith_t; | 85 | typedef 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 46dd2a0d7..f909a0d96 100644 --- a/coreutils/factor.c +++ b/coreutils/factor.c | |||
@@ -124,7 +124,7 @@ static NOINLINE void print_w(wide_t n) | |||
124 | { | 124 | { |
125 | unsigned rep = square_count; | 125 | unsigned rep = square_count; |
126 | do | 126 | do |
127 | printf(" %llu", n); | 127 | printf(" %"LL_FMT"u", n); |
128 | while (--rep != 0); | 128 | while (--rep != 0); |
129 | } | 129 | } |
130 | static NOINLINE void print_h(half_t n) | 130 | static NOINLINE void print_h(half_t n) |
@@ -226,7 +226,7 @@ static void factorize_numstr(const char *numstr) | |||
226 | N = bb_strtoull(numstr, NULL, 10); | 226 | N = bb_strtoull(numstr, NULL, 10); |
227 | if (errno) | 227 | if (errno) |
228 | bb_show_usage(); | 228 | bb_show_usage(); |
229 | printf("%llu:", N); | 229 | printf("%"LL_FMT"u:", N); |
230 | square_count = 1; | 230 | square_count = 1; |
231 | factorize(N); | 231 | factorize(N); |
232 | } | 232 | } |
diff --git a/coreutils/ls.c b/coreutils/ls.c index b69b80460..3c659294c 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -316,6 +316,9 @@ struct dnode { | |||
316 | int dn_rdev_min; | 316 | int dn_rdev_min; |
317 | // dev_t dn_dev; | 317 | // dev_t dn_dev; |
318 | // blksize_t dn_blksize; | 318 | // blksize_t dn_blksize; |
319 | #if ENABLE_PLATFORM_MINGW32 | ||
320 | DWORD dn_attr; | ||
321 | #endif | ||
319 | }; | 322 | }; |
320 | 323 | ||
321 | struct globals { | 324 | struct globals { |
@@ -497,7 +500,11 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
497 | lpath = xmalloc_readlink_or_warn(dn->fullname); | 500 | lpath = xmalloc_readlink_or_warn(dn->fullname); |
498 | 501 | ||
499 | if (opt & OPT_i) /* show inode# */ | 502 | if (opt & OPT_i) /* show inode# */ |
500 | column += printf("%7llu ", (long long) dn->dn_ino); | 503 | #if !ENABLE_FEATURE_EXTRA_FILE_DATA |
504 | column += printf("%7"LL_FMT"u ", (long long) dn->dn_ino); | ||
505 | #else | ||
506 | column += printf("%19"LL_FMT"u ", (long long) dn->dn_ino); | ||
507 | #endif | ||
501 | if (opt & OPT_s) { /* show allocated blocks */ | 508 | if (opt & OPT_s) { /* show allocated blocks */ |
502 | if (opt & OPT_h) { | 509 | if (opt & OPT_h) { |
503 | column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ", | 510 | column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ", |
@@ -659,7 +666,11 @@ static void display_files(struct dnode **dn, unsigned nfiles) | |||
659 | } | 666 | } |
660 | column_width += 2 | 667 | column_width += 2 |
661 | + ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */ | 668 | + ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */ |
669 | #if !ENABLE_FEATURE_EXTRA_FILE_DATA | ||
662 | + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ | 670 | + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ |
671 | #else | ||
672 | + ((option_mask32 & OPT_i) ? 20 : 0) /* inode# width */ | ||
673 | #endif | ||
663 | + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */ | 674 | + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */ |
664 | ; | 675 | ; |
665 | ncols = (unsigned)G_terminal_width / column_width; | 676 | ncols = (unsigned)G_terminal_width / column_width; |
@@ -740,6 +751,9 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f | |||
740 | 751 | ||
741 | /* cur->dstat = statbuf: */ | 752 | /* cur->dstat = statbuf: */ |
742 | cur->dn_mode = statbuf.st_mode ; | 753 | cur->dn_mode = statbuf.st_mode ; |
754 | #if ENABLE_PLATFORM_MINGW32 | ||
755 | cur->dn_attr = statbuf.st_attr ; | ||
756 | #endif | ||
743 | cur->dn_size = statbuf.st_size ; | 757 | cur->dn_size = statbuf.st_size ; |
744 | #if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES | 758 | #if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES |
745 | cur->dn_time = statbuf.st_mtime ; | 759 | cur->dn_time = statbuf.st_mtime ; |
@@ -949,9 +963,20 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p) | |||
949 | continue; /* if only -A, skip . and .. but show other dotfiles */ | 963 | continue; /* if only -A, skip . and .. but show other dotfiles */ |
950 | } | 964 | } |
951 | } | 965 | } |
966 | #if ENABLE_PLATFORM_MINGW32 | ||
967 | if (has_dos_drive_prefix(path) && path[2] == '\0') | ||
968 | fullname = xasprintf("%s%s", path, entry->d_name); | ||
969 | else | ||
970 | #endif | ||
952 | fullname = concat_path_file(path, entry->d_name); | 971 | fullname = concat_path_file(path, entry->d_name); |
953 | cur = my_stat(fullname, bb_basename(fullname), 0); | 972 | cur = my_stat(fullname, bb_basename(fullname), 0); |
973 | #if !ENABLE_PLATFORM_MINGW32 | ||
954 | if (!cur) { | 974 | if (!cur) { |
975 | #else | ||
976 | if (!cur || ((cur->dn_attr & FILE_ATTRIBUTE_HIDDEN) && | ||
977 | !(option_mask32 & (OPT_a|OPT_A)))) { | ||
978 | /* skip invalid or hidden files */ | ||
979 | #endif | ||
955 | free(fullname); | 980 | free(fullname); |
956 | continue; | 981 | continue; |
957 | } | 982 | } |
@@ -1060,6 +1085,18 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first) | |||
1060 | } | 1085 | } |
1061 | } | 1086 | } |
1062 | 1087 | ||
1088 | #if ENABLE_PLATFORM_MINGW32 | ||
1089 | static char *fix_backslash(char *p) | ||
1090 | { | ||
1091 | const char *flag = getenv("BB_FIX_BACKSLASH"); | ||
1092 | int value = flag ? atoi(flag) : 0; | ||
1093 | |||
1094 | if (value == 1) | ||
1095 | bs_to_slash(p); | ||
1096 | return p; | ||
1097 | } | ||
1098 | #endif | ||
1099 | |||
1063 | 1100 | ||
1064 | int ls_main(int argc UNUSED_PARAM, char **argv) | 1101 | int ls_main(int argc UNUSED_PARAM, char **argv) |
1065 | { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */ | 1102 | { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */ |
@@ -1204,6 +1241,12 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1204 | option_mask32 |= OPT_dirs_first; | 1241 | option_mask32 |= OPT_dirs_first; |
1205 | } | 1242 | } |
1206 | 1243 | ||
1244 | #if ENABLE_FEATURE_EXTRA_FILE_DATA | ||
1245 | /* Enable accurate link counts for directories */ | ||
1246 | if (opt & OPT_l) | ||
1247 | count_subdirs(NULL); | ||
1248 | #endif | ||
1249 | |||
1207 | argv += optind; | 1250 | argv += optind; |
1208 | if (!argv[0]) | 1251 | if (!argv[0]) |
1209 | *--argv = (char*)"."; | 1252 | *--argv = (char*)"."; |
@@ -1215,6 +1258,9 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1215 | dn = NULL; | 1258 | dn = NULL; |
1216 | nfiles = 0; | 1259 | nfiles = 0; |
1217 | do { | 1260 | do { |
1261 | #if ENABLE_PLATFORM_MINGW32 | ||
1262 | *argv = fix_backslash(*argv); | ||
1263 | #endif | ||
1218 | cur = my_stat(*argv, *argv, | 1264 | cur = my_stat(*argv, *argv, |
1219 | /* follow links on command line unless -l, -i, -s or -F: */ | 1265 | /* follow links on command line unless -l, -i, -s or -F: */ |
1220 | !(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F)) | 1266 | !(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F)) |
diff --git a/coreutils/nproc.c b/coreutils/nproc.c index bb9bc56c5..fb673a210 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c | |||
@@ -29,7 +29,11 @@ | |||
29 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 29 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
30 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 30 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
31 | { | 31 | { |
32 | #if !ENABLE_PLATFORM_MINGW32 | ||
32 | unsigned long mask[1024]; | 33 | unsigned long mask[1024]; |
34 | #else | ||
35 | DWORD_PTR affinity, process_affinity, system_affinity; | ||
36 | #endif | ||
33 | int count = 0; | 37 | int count = 0; |
34 | #if ENABLE_LONG_OPTS | 38 | #if ENABLE_LONG_OPTS |
35 | int ignore = 0; | 39 | int ignore = 0; |
@@ -38,7 +42,10 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
38 | "all\0" No_argument "\xff" | 42 | "all\0" No_argument "\xff" |
39 | , &ignore | 43 | , &ignore |
40 | ); | 44 | ); |
45 | #endif | ||
41 | 46 | ||
47 | #if !ENABLE_PLATFORM_MINGW32 | ||
48 | #if ENABLE_LONG_OPTS | ||
42 | if (opts & (1 << 1)) { | 49 | if (opts & (1 << 1)) { |
43 | DIR *cpusd = opendir("/sys/devices/system/cpu"); | 50 | DIR *cpusd = opendir("/sys/devices/system/cpu"); |
44 | if (cpusd) { | 51 | if (cpusd) { |
@@ -63,6 +70,17 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
63 | } | 70 | } |
64 | } | 71 | } |
65 | } | 72 | } |
73 | #else /* ENABLE_PLATFORM_MINGW32 */ | ||
74 | if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity, | ||
75 | &system_affinity)) { | ||
76 | affinity = (ENABLE_LONG_OPTS && opts & (1 << 1)) ? | ||
77 | system_affinity : process_affinity; | ||
78 | while (affinity) { | ||
79 | count += affinity & 1; | ||
80 | affinity >>= 1; | ||
81 | } | ||
82 | } | ||
83 | #endif /* ENABLE_PLATFORM_MINGW32 */ | ||
66 | 84 | ||
67 | IF_LONG_OPTS(count -= ignore;) | 85 | IF_LONG_OPTS(count -= ignore;) |
68 | if (count <= 0) | 86 | if (count <= 0) |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 5b5e56a21..1830aca83 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 | ||
104 | enum size_spec { | 111 | enum size_spec { |
105 | NO_SIZE, | 112 | NO_SIZE, |
106 | CHAR, | 113 | CHAR, |
diff --git a/coreutils/printf.c b/coreutils/printf.c index b89df67f9..411edd5b9 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -152,6 +152,71 @@ static double my_xstrtod(const char *arg) | |||
152 | return result; | 152 | return result; |
153 | } | 153 | } |
154 | 154 | ||
155 | #if ENABLE_PLATFORM_MINGW32 | ||
156 | static int buflen = 0; | ||
157 | static int bufmax = 0; | ||
158 | static char *buffer = NULL; | ||
159 | |||
160 | static void my_flush(void) | ||
161 | { | ||
162 | if (buffer) | ||
163 | full_write(STDOUT_FILENO, buffer, buflen); | ||
164 | free(buffer); | ||
165 | buffer = NULL; | ||
166 | buflen = bufmax = 0; | ||
167 | } | ||
168 | |||
169 | static void copy_to_buffer(const char *str, int len) | ||
170 | { | ||
171 | char *newbuf; | ||
172 | |||
173 | if (buflen + len >= bufmax) { | ||
174 | bufmax += 256 + len; | ||
175 | if ((newbuf = realloc(buffer, bufmax)) == NULL) { | ||
176 | my_flush(); | ||
177 | return; | ||
178 | } | ||
179 | buffer = newbuf; | ||
180 | } | ||
181 | memcpy(buffer + buflen, str, len); | ||
182 | buflen += len; | ||
183 | |||
184 | if (buflen > 40 && buffer[buflen-1] == '\n') | ||
185 | my_flush(); | ||
186 | } | ||
187 | |||
188 | static int my_putchar(int ch) | ||
189 | { | ||
190 | char str[1] = { (char)ch }; | ||
191 | copy_to_buffer(str, 1); | ||
192 | return ch; | ||
193 | } | ||
194 | |||
195 | static int my_printf(const char *format, ...) | ||
196 | { | ||
197 | va_list list; | ||
198 | char *str; | ||
199 | int len; | ||
200 | |||
201 | va_start(list, format); | ||
202 | len = vasprintf(&str, format, list); | ||
203 | va_end(list); | ||
204 | |||
205 | if (len >= 0) { | ||
206 | copy_to_buffer(str, len); | ||
207 | free(str); | ||
208 | } | ||
209 | return len; | ||
210 | } | ||
211 | |||
212 | #undef bb_putchar | ||
213 | #undef putchar | ||
214 | #undef printf | ||
215 | #define bb_putchar(c) my_putchar(c) | ||
216 | #define putchar(c) my_putchar(c) | ||
217 | #define printf(...) my_printf(__VA_ARGS__) | ||
218 | #endif | ||
219 | |||
155 | /* Handles %b; return 1 if output is to be short-circuited by \c */ | 220 | /* Handles %b; return 1 if output is to be short-circuited by \c */ |
156 | static int print_esc_string(const char *str) | 221 | static int print_esc_string(const char *str) |
157 | { | 222 | { |
@@ -444,6 +509,9 @@ int printf_main(int argc UNUSED_PARAM, char **argv) | |||
444 | do { | 509 | do { |
445 | argv = argv2; | 510 | argv = argv2; |
446 | argv2 = print_formatted(format, argv, &conv_err); | 511 | argv2 = print_formatted(format, argv, &conv_err); |
512 | #if ENABLE_PLATFORM_MINGW32 | ||
513 | my_flush(); | ||
514 | #endif | ||
447 | } while (argv2 > argv && *argv2); | 515 | } while (argv2 > argv && *argv2); |
448 | 516 | ||
449 | /* coreutils compat (bash doesn't do this): | 517 | /* coreutils compat (bash doesn't do this): |
diff --git a/coreutils/shred.c b/coreutils/shred.c index 04bf87229..794d7b815 100644 --- a/coreutils/shred.c +++ b/coreutils/shred.c | |||
@@ -60,9 +60,9 @@ int shred_main(int argc UNUSED_PARAM, char **argv) | |||
60 | opt = getopt32(argv, "^" "fuzn:+vxs:" "\0" "-1"/*min 1 arg*/, &num_iter, &opt_s); | 60 | opt = getopt32(argv, "^" "fuzn:+vxs:" "\0" "-1"/*min 1 arg*/, &num_iter, &opt_s); |
61 | argv += optind; | 61 | argv += optind; |
62 | 62 | ||
63 | zero_fd = xopen("/dev/zero", O_RDONLY); | 63 | zero_fd = MINGW_SPECIAL(xopen)("/dev/zero", O_RDONLY); |
64 | if (num_iter != 0) | 64 | if (num_iter != 0) |
65 | rand_fd = xopen("/dev/urandom", O_RDONLY); | 65 | rand_fd = MINGW_SPECIAL(xopen)("/dev/urandom", O_RDONLY); |
66 | 66 | ||
67 | for (;;) { | 67 | for (;;) { |
68 | struct stat sb; | 68 | struct stat sb; |
@@ -102,8 +102,14 @@ int shred_main(int argc UNUSED_PARAM, char **argv) | |||
102 | } | 102 | } |
103 | if (opt & OPT_u) { | 103 | if (opt & OPT_u) { |
104 | ftruncate(fd, 0); | 104 | ftruncate(fd, 0); |
105 | #if ENABLE_PLATFORM_MINGW32 | ||
106 | xclose(fd); | ||
107 | #endif | ||
105 | xunlink(fname); | 108 | xunlink(fname); |
106 | } | 109 | } |
110 | #if ENABLE_PLATFORM_MINGW32 | ||
111 | else | ||
112 | #endif | ||
107 | xclose(fd); | 113 | xclose(fd); |
108 | } | 114 | } |
109 | 115 | ||
diff --git a/coreutils/split.c b/coreutils/split.c index 3fcfd95f2..9393423a1 100644 --- a/coreutils/split.c +++ b/coreutils/split.c | |||
@@ -78,8 +78,10 @@ static char *next_file(char *old, unsigned suffix_len) | |||
78 | return old; | 78 | return old; |
79 | } | 79 | } |
80 | 80 | ||
81 | #if !ENABLE_PLATFORM_MINGW32 | ||
81 | #define read_buffer bb_common_bufsiz1 | 82 | #define read_buffer bb_common_bufsiz1 |
82 | enum { READ_BUFFER_SIZE = COMMON_BUFSIZE - 1 }; | 83 | enum { READ_BUFFER_SIZE = COMMON_BUFSIZE - 1 }; |
84 | #endif | ||
83 | 85 | ||
84 | #define SPLIT_OPT_l (1<<0) | 86 | #define SPLIT_OPT_l (1<<0) |
85 | #define SPLIT_OPT_b (1<<1) | 87 | #define SPLIT_OPT_b (1<<1) |
@@ -97,8 +99,12 @@ int split_main(int argc UNUSED_PARAM, char **argv) | |||
97 | unsigned opt; | 99 | unsigned opt; |
98 | ssize_t bytes_read, to_write; | 100 | ssize_t bytes_read, to_write; |
99 | char *src; | 101 | char *src; |
100 | 102 | #if ENABLE_PLATFORM_MINGW32 | |
103 | size_t READ_BUFFER_SIZE = 16*1024; | ||
104 | char *read_buffer = xmalloc(16*1024); | ||
105 | #else | ||
101 | setup_common_bufsiz(); | 106 | setup_common_bufsiz(); |
107 | #endif | ||
102 | 108 | ||
103 | opt = getopt32(argv, "^" | 109 | opt = getopt32(argv, "^" |
104 | "l:b:a:+" /* -a N */ | 110 | "l:b:a:+" /* -a N */ |
diff --git a/coreutils/stat.c b/coreutils/stat.c index 2c2909e7e..dc20c2356 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -190,6 +190,7 @@ FS_TYPE(0x012FF7B4, "xenix") \ | |||
190 | FS_TYPE(0x012FF7B5, "sysv4") \ | 190 | FS_TYPE(0x012FF7B5, "sysv4") \ |
191 | FS_TYPE(0x012FF7B6, "sysv2") \ | 191 | FS_TYPE(0x012FF7B6, "sysv2") \ |
192 | FS_TYPE(0x012FF7B7, "coh") \ | 192 | FS_TYPE(0x012FF7B7, "coh") \ |
193 | IF_PLATFORM_MINGW32(FS_TYPE(0x15013346, "udf")) \ | ||
193 | FS_TYPE(0x00011954, "ufs") \ | 194 | FS_TYPE(0x00011954, "ufs") \ |
194 | FS_TYPE(0x012FD16D, "xia") \ | 195 | FS_TYPE(0x012FD16D, "xia") \ |
195 | FS_TYPE(0x5346544e, "ntfs") \ | 196 | FS_TYPE(0x5346544e, "ntfs") \ |
@@ -784,6 +785,10 @@ int stat_main(int argc UNUSED_PARAM, char **argv) | |||
784 | selinux_or_die(); | 785 | selinux_or_die(); |
785 | } | 786 | } |
786 | #endif | 787 | #endif |
788 | #if ENABLE_FEATURE_EXTRA_FILE_DATA | ||
789 | /* Enable accurate link counts for directories */ | ||
790 | count_subdirs(NULL); | ||
791 | #endif | ||
787 | ok = 1; | 792 | ok = 1; |
788 | argv += optind; | 793 | argv += optind; |
789 | for (i = 0; argv[i]; ++i) | 794 | for (i = 0; argv[i]; ++i) |
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 06108f315..8f306529f 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c | |||
@@ -42,11 +42,39 @@ | |||
42 | //usage: "[-s SIG] [-k KILL_SECS] SECS PROG ARGS" | 42 | //usage: "[-s SIG] [-k KILL_SECS] SECS PROG ARGS" |
43 | //usage:#define timeout_full_usage "\n\n" | 43 | //usage:#define timeout_full_usage "\n\n" |
44 | //usage: "Run PROG. Send SIG to it if it is not gone in SECS seconds.\n" | 44 | //usage: "Run PROG. Send SIG to it if it is not gone in SECS seconds.\n" |
45 | //usage: "Default SIG: TERM." | 45 | //usage: IF_NOT_PLATFORM_MINGW32("Default SIG: TERM.") |
46 | //usage: IF_PLATFORM_MINGW32("Default SIG: TERM.\n") | ||
46 | //usage: "If it still exists in KILL_SECS seconds, send KILL.\n" | 47 | //usage: "If it still exists in KILL_SECS seconds, send KILL.\n" |
47 | 48 | ||
48 | #include "libbb.h" | 49 | #include "libbb.h" |
49 | 50 | ||
51 | #if ENABLE_PLATFORM_MINGW32 | ||
52 | static HANDLE child = INVALID_HANDLE_VALUE; | ||
53 | |||
54 | static void kill_child(void) | ||
55 | { | ||
56 | if (child != INVALID_HANDLE_VALUE) { | ||
57 | kill_signal_by_handle(child, SIGTERM); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | /* Return TRUE if child exits before timeout expires */ | ||
62 | static NOINLINE int timeout_wait(int timeout, HANDLE proc, DWORD *status) | ||
63 | { | ||
64 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ | ||
65 | while (1) { | ||
66 | sleep1(); | ||
67 | if (--timeout <= 0) | ||
68 | break; | ||
69 | if (WaitForSingleObject(proc, 0) == WAIT_OBJECT_0) { | ||
70 | /* process is gone */ | ||
71 | GetExitCodeProcess(proc, status); | ||
72 | return TRUE; | ||
73 | } | ||
74 | } | ||
75 | return FALSE; | ||
76 | } | ||
77 | #else | ||
50 | static NOINLINE int timeout_wait(int timeout, pid_t pid) | 78 | static NOINLINE int timeout_wait(int timeout, pid_t pid) |
51 | { | 79 | { |
52 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ | 80 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ |
@@ -61,13 +89,19 @@ static NOINLINE int timeout_wait(int timeout, pid_t pid) | |||
61 | } | 89 | } |
62 | return EXIT_FAILURE; | 90 | return EXIT_FAILURE; |
63 | } | 91 | } |
92 | #endif | ||
64 | 93 | ||
65 | int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 94 | int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
66 | int timeout_main(int argc UNUSED_PARAM, char **argv) | 95 | int timeout_main(int argc UNUSED_PARAM, char **argv) |
67 | { | 96 | { |
68 | int signo; | 97 | int signo; |
98 | #if !ENABLE_PLATFORM_MINGW32 | ||
69 | int status; | 99 | int status; |
70 | int parent = 0; | 100 | int parent = 0; |
101 | #else | ||
102 | intptr_t ret; | ||
103 | DWORD status = EXIT_SUCCESS; | ||
104 | #endif | ||
71 | int timeout; | 105 | int timeout; |
72 | int kill_timeout; | 106 | int kill_timeout; |
73 | pid_t pid; | 107 | pid_t pid; |
@@ -77,15 +111,27 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
77 | const char *opt_s = "TERM"; | 111 | const char *opt_s = "TERM"; |
78 | char *opt_k = NULL; | 112 | char *opt_k = NULL; |
79 | 113 | ||
114 | #if ENABLE_PLATFORM_MINGW32 | ||
115 | xfunc_error_retval = 125; | ||
116 | #endif | ||
117 | |||
80 | /* -p option is not documented, it is needed to support NOMMU. */ | 118 | /* -p option is not documented, it is needed to support NOMMU. */ |
81 | 119 | ||
82 | /* -t SECONDS; -p PARENT_PID */ | 120 | /* -t SECONDS; -p PARENT_PID */ |
83 | /* '+': stop at first non-option */ | 121 | /* '+': stop at first non-option */ |
122 | #if !ENABLE_PLATFORM_MINGW32 | ||
84 | getopt32(argv, "+s:k:" USE_FOR_NOMMU("p:+"), &opt_s, &opt_k, &parent); | 123 | getopt32(argv, "+s:k:" USE_FOR_NOMMU("p:+"), &opt_s, &opt_k, &parent); |
124 | #else | ||
125 | getopt32(argv, "+s:k:", &opt_s, &opt_k); | ||
126 | #endif | ||
85 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ | 127 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ |
86 | 128 | ||
87 | signo = get_signum(opt_s); | 129 | signo = get_signum(opt_s); |
130 | #if !ENABLE_PLATFORM_MINGW32 | ||
88 | if (signo < 0) | 131 | if (signo < 0) |
132 | #else | ||
133 | if (!is_valid_signal(signo)) | ||
134 | #endif | ||
89 | bb_error_msg_and_die("unknown signal '%s'", opt_s); | 135 | bb_error_msg_and_die("unknown signal '%s'", opt_s); |
90 | 136 | ||
91 | kill_timeout = 0; | 137 | kill_timeout = 0; |
@@ -98,6 +144,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
98 | if (!argv[optind]) /* no PROG? */ | 144 | if (!argv[optind]) /* no PROG? */ |
99 | bb_show_usage(); | 145 | bb_show_usage(); |
100 | 146 | ||
147 | #if !ENABLE_PLATFORM_MINGW32 | ||
101 | /* We want to create a grandchild which will watch | 148 | /* We want to create a grandchild which will watch |
102 | * and kill the grandparent. Other methods: | 149 | * and kill the grandparent. Other methods: |
103 | * making parent watch child disrupts parent<->child link | 150 | * making parent watch child disrupts parent<->child link |
@@ -150,4 +197,31 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
150 | argv[1] = sv2; | 197 | argv[1] = sv2; |
151 | #endif | 198 | #endif |
152 | BB_EXECVP_or_die(argv); | 199 | BB_EXECVP_or_die(argv); |
200 | #else /* ENABLE_PLATFORM_MINGW32 */ | ||
201 | argv += optind; | ||
202 | if ((ret=mingw_spawn_proc((const char **)argv)) == -1) { | ||
203 | xfunc_error_retval = errno == EACCES ? 126 : 127; | ||
204 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); | ||
205 | } | ||
206 | |||
207 | child = (HANDLE)ret; | ||
208 | atexit(kill_child); | ||
209 | if (timeout_wait(timeout, child, &status)) | ||
210 | goto finish; | ||
211 | status = signo == SIGKILL ? 137 : 124; | ||
212 | |||
213 | pid = (pid_t)GetProcessId(child); | ||
214 | kill(pid, signo); | ||
215 | |||
216 | if (kill_timeout > 0) { | ||
217 | if (timeout_wait(kill_timeout, child, &status)) | ||
218 | goto finish; | ||
219 | kill(pid, SIGKILL); | ||
220 | status = 137; | ||
221 | } | ||
222 | finish: | ||
223 | CloseHandle(child); | ||
224 | child = INVALID_HANDLE_VALUE; | ||
225 | return status; | ||
226 | #endif | ||
153 | } | 227 | } |
diff --git a/coreutils/yes.c b/coreutils/yes.c index 161db82c0..7eb8ac1ba 100644 --- a/coreutils/yes.c +++ b/coreutils/yes.c | |||
@@ -31,6 +31,11 @@ | |||
31 | 31 | ||
32 | #include "libbb.h" | 32 | #include "libbb.h" |
33 | 33 | ||
34 | #if ENABLE_PLATFORM_MINGW32 | ||
35 | # undef putchar | ||
36 | # define putchar(c) winansi_fputc(c, stdout) | ||
37 | #endif | ||
38 | |||
34 | int yes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 39 | int yes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
35 | int yes_main(int argc UNUSED_PARAM, char **argv) | 40 | int yes_main(int argc UNUSED_PARAM, char **argv) |
36 | { | 41 | { |