diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/date.c | 25 | ||||
-rw-r--r-- | coreutils/dd.c | 38 | ||||
-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 | 44 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 7 | ||||
-rw-r--r-- | coreutils/printf.c | 64 | ||||
-rw-r--r-- | coreutils/shred.c | 10 | ||||
-rw-r--r-- | coreutils/stat.c | 9 | ||||
-rw-r--r-- | coreutils/sum.c | 4 | ||||
-rw-r--r-- | coreutils/timeout.c | 54 | ||||
-rw-r--r-- | coreutils/yes.c | 4 |
13 files changed, 256 insertions, 11 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index 7061f1719..d64ff94b9 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 24d7f0b84..c150ef5bc 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -93,6 +93,9 @@ | |||
93 | //usage: "\n status=none Suppress all output" | 93 | //usage: "\n status=none Suppress all output" |
94 | //usage: ) | 94 | //usage: ) |
95 | //usage: "\n" | 95 | //usage: "\n" |
96 | //usage: IF_PLATFORM_MINGW32( | ||
97 | //usage: "\nif=/dev/zero and if=/dev/urandom are supported" | ||
98 | //usage: ) | ||
96 | //usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G" | 99 | //usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G" |
97 | //usage: | 100 | //usage: |
98 | //usage:#define dd_example_usage | 101 | //usage:#define dd_example_usage |
@@ -298,9 +301,11 @@ static int parse_comma_flags(char *val, const char *words, const char *error_in) | |||
298 | 301 | ||
299 | static void *alloc_buf(size_t size) | 302 | static void *alloc_buf(size_t size) |
300 | { | 303 | { |
304 | #if !ENABLE_PLATFORM_MINGW32 | ||
301 | /* Important for "{i,o}flag=direct" - buffers must be page aligned */ | 305 | /* Important for "{i,o}flag=direct" - buffers must be page aligned */ |
302 | if (size >= bb_getpagesize()) | 306 | if (size >= bb_getpagesize()) |
303 | return xmmap_anon(size); | 307 | return xmmap_anon(size); |
308 | #endif | ||
304 | return xmalloc(size); | 309 | return xmalloc(size); |
305 | } | 310 | } |
306 | 311 | ||
@@ -419,11 +424,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
419 | #if ENABLE_FEATURE_DD_IBS_OBS | 424 | #if ENABLE_FEATURE_DD_IBS_OBS |
420 | if (what == OP_ibs) { | 425 | if (what == OP_ibs) { |
421 | /* Must fit into positive ssize_t */ | 426 | /* Must fit into positive ssize_t */ |
422 | ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); | 427 | ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes); |
423 | /*continue;*/ | 428 | /*continue;*/ |
424 | } | 429 | } |
425 | if (what == OP_obs) { | 430 | if (what == OP_obs) { |
426 | obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); | 431 | obs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes); |
427 | /*continue;*/ | 432 | /*continue;*/ |
428 | } | 433 | } |
429 | if (what == OP_conv) { | 434 | if (what == OP_conv) { |
@@ -440,7 +445,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
440 | } | 445 | } |
441 | #endif | 446 | #endif |
442 | if (what == OP_bs) { | 447 | if (what == OP_bs) { |
443 | ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); | 448 | ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes); |
444 | obs = ibs; | 449 | obs = ibs; |
445 | /*continue;*/ | 450 | /*continue;*/ |
446 | } | 451 | } |
@@ -500,7 +505,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
500 | if (G.flags & FLAG_IDIRECT) | 505 | if (G.flags & FLAG_IDIRECT) |
501 | iflag |= O_DIRECT; | 506 | iflag |= O_DIRECT; |
502 | #endif | 507 | #endif |
508 | #if !ENABLE_PLATFORM_MINGW32 | ||
503 | xmove_fd(xopen(infile, iflag), ifd); | 509 | xmove_fd(xopen(infile, iflag), ifd); |
510 | #else | ||
511 | xmove_fd(mingw_xopen(infile, iflag), ifd); | ||
512 | update_dev_fd(get_dev_type(infile), ifd); | ||
513 | #endif | ||
504 | } else { | 514 | } else { |
505 | infile = bb_msg_standard_input; | 515 | infile = bb_msg_standard_input; |
506 | } | 516 | } |
@@ -517,6 +527,27 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
517 | #endif | 527 | #endif |
518 | xmove_fd(xopen(outfile, oflag), ofd); | 528 | xmove_fd(xopen(outfile, oflag), ofd); |
519 | 529 | ||
530 | #if ENABLE_PLATFORM_MINGW32 | ||
531 | { | ||
532 | off_t len = (off_t)seek * ((G.flags & FLAG_SEEK_BYTES) ? 1 : obs); | ||
533 | struct stat st; | ||
534 | int ret = fstat(ofd, &st); | ||
535 | |||
536 | if (ret == 0 && !(G.flags & FLAG_APPEND) && len > st.st_size) | ||
537 | make_sparse(ofd, st.st_size, len); | ||
538 | |||
539 | if (seek && !(G.flags & FLAG_NOTRUNC)) { | ||
540 | if (ftruncate(ofd, len) < 0) { | ||
541 | if (ret < 0 | ||
542 | || S_ISREG(st.st_mode) | ||
543 | || S_ISDIR(st.st_mode) | ||
544 | ) { | ||
545 | goto die_outfile; | ||
546 | } | ||
547 | } | ||
548 | } | ||
549 | } | ||
550 | #else | ||
520 | if (seek && !(G.flags & FLAG_NOTRUNC)) { | 551 | if (seek && !(G.flags & FLAG_NOTRUNC)) { |
521 | size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs; | 552 | size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs; |
522 | if (ftruncate(ofd, seek * blocksz) < 0) { | 553 | if (ftruncate(ofd, seek * blocksz) < 0) { |
@@ -530,6 +561,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
530 | } | 561 | } |
531 | } | 562 | } |
532 | } | 563 | } |
564 | #endif | ||
533 | } else { | 565 | } else { |
534 | outfile = bb_msg_standard_output; | 566 | outfile = bb_msg_standard_output; |
535 | } | 567 | } |
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 b247f08db..c11505d13 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 de8ea4e11..a7a5a5030 100644 --- a/coreutils/factor.c +++ b/coreutils/factor.c | |||
@@ -125,7 +125,7 @@ static NOINLINE void print_w(wide_t n) | |||
125 | { | 125 | { |
126 | unsigned rep = square_count; | 126 | unsigned rep = square_count; |
127 | do | 127 | do |
128 | printf(" %llu", n); | 128 | printf(" %"LL_FMT"u", n); |
129 | while (--rep != 0); | 129 | while (--rep != 0); |
130 | } | 130 | } |
131 | static NOINLINE void print_h(half_t n) | 131 | static NOINLINE void print_h(half_t n) |
@@ -227,7 +227,7 @@ static void factorize_numstr(const char *numstr) | |||
227 | N = bb_strtoull(numstr, NULL, 10); | 227 | N = bb_strtoull(numstr, NULL, 10); |
228 | if (errno) | 228 | if (errno) |
229 | bb_show_usage(); | 229 | bb_show_usage(); |
230 | printf("%llu:", N); | 230 | printf("%"LL_FMT"u:", N); |
231 | square_count = 1; | 231 | square_count = 1; |
232 | factorize(N); | 232 | factorize(N); |
233 | } | 233 | } |
diff --git a/coreutils/ls.c b/coreutils/ls.c index e5375a61a..2f9338f19 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 { |
@@ -492,12 +495,18 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
492 | /* Do readlink early, so that if it fails, error message | 495 | /* Do readlink early, so that if it fails, error message |
493 | * does not appear *inside* the "ls -l" line */ | 496 | * does not appear *inside* the "ls -l" line */ |
494 | lpath = NULL; | 497 | lpath = NULL; |
498 | #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 | ||
495 | if (opt & OPT_l) | 499 | if (opt & OPT_l) |
496 | if (S_ISLNK(dn->dn_mode)) | 500 | if (S_ISLNK(dn->dn_mode)) |
497 | lpath = xmalloc_readlink_or_warn(dn->fullname); | 501 | lpath = xmalloc_readlink_or_warn(dn->fullname); |
502 | #endif | ||
498 | 503 | ||
499 | if (opt & OPT_i) /* show inode# */ | 504 | if (opt & OPT_i) /* show inode# */ |
500 | column += printf("%7llu ", (long long) dn->dn_ino); | 505 | #if !ENABLE_FEATURE_EXTRA_FILE_DATA |
506 | column += printf("%7"LL_FMT"u ", (long long) dn->dn_ino); | ||
507 | #else | ||
508 | column += printf("%19"LL_FMT"u ", (long long) dn->dn_ino); | ||
509 | #endif | ||
501 | //TODO: -h should affect -s too: | 510 | //TODO: -h should affect -s too: |
502 | if (opt & OPT_s) /* show allocated blocks */ | 511 | if (opt & OPT_s) /* show allocated blocks */ |
503 | column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); | 512 | column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); |
@@ -651,7 +660,11 @@ static void display_files(struct dnode **dn, unsigned nfiles) | |||
651 | } | 660 | } |
652 | column_width += 2 | 661 | column_width += 2 |
653 | + ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */ | 662 | + ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */ |
663 | #if !ENABLE_FEATURE_EXTRA_FILE_DATA | ||
654 | + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ | 664 | + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ |
665 | #else | ||
666 | + ((option_mask32 & OPT_i) ? 20 : 0) /* inode# width */ | ||
667 | #endif | ||
655 | + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */ | 668 | + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */ |
656 | ; | 669 | ; |
657 | ncols = (unsigned)G_terminal_width / column_width; | 670 | ncols = (unsigned)G_terminal_width / column_width; |
@@ -732,6 +745,9 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f | |||
732 | 745 | ||
733 | /* cur->dstat = statbuf: */ | 746 | /* cur->dstat = statbuf: */ |
734 | cur->dn_mode = statbuf.st_mode ; | 747 | cur->dn_mode = statbuf.st_mode ; |
748 | #if ENABLE_PLATFORM_MINGW32 | ||
749 | cur->dn_attr = statbuf.st_attr ; | ||
750 | #endif | ||
735 | cur->dn_size = statbuf.st_size ; | 751 | cur->dn_size = statbuf.st_size ; |
736 | #if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES | 752 | #if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES |
737 | cur->dn_time = statbuf.st_mtime ; | 753 | cur->dn_time = statbuf.st_mtime ; |
@@ -941,9 +957,20 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p) | |||
941 | continue; /* if only -A, skip . and .. but show other dotfiles */ | 957 | continue; /* if only -A, skip . and .. but show other dotfiles */ |
942 | } | 958 | } |
943 | } | 959 | } |
960 | #if ENABLE_PLATFORM_MINGW32 | ||
961 | if (has_dos_drive_prefix(path) && path[2] == '\0') | ||
962 | fullname = xasprintf("%s%s", path, entry->d_name); | ||
963 | else | ||
964 | #endif | ||
944 | fullname = concat_path_file(path, entry->d_name); | 965 | fullname = concat_path_file(path, entry->d_name); |
945 | cur = my_stat(fullname, bb_basename(fullname), 0); | 966 | cur = my_stat(fullname, bb_basename(fullname), 0); |
967 | #if !ENABLE_PLATFORM_MINGW32 | ||
946 | if (!cur) { | 968 | if (!cur) { |
969 | #else | ||
970 | if (!cur || ((cur->dn_attr & FILE_ATTRIBUTE_HIDDEN) && | ||
971 | !(option_mask32 & (OPT_a|OPT_A)))) { | ||
972 | /* skip invalid or hidden files */ | ||
973 | #endif | ||
947 | free(fullname); | 974 | free(fullname); |
948 | continue; | 975 | continue; |
949 | } | 976 | } |
@@ -1052,6 +1079,18 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first) | |||
1052 | } | 1079 | } |
1053 | } | 1080 | } |
1054 | 1081 | ||
1082 | #if ENABLE_PLATFORM_MINGW32 | ||
1083 | static char *fix_backslash(char *p) | ||
1084 | { | ||
1085 | const char *flag = getenv("BB_FIX_BACKSLASH"); | ||
1086 | int value = flag ? atoi(flag) : 0; | ||
1087 | |||
1088 | if (value == 1) | ||
1089 | bs_to_slash(p); | ||
1090 | return p; | ||
1091 | } | ||
1092 | #endif | ||
1093 | |||
1055 | 1094 | ||
1056 | int ls_main(int argc UNUSED_PARAM, char **argv) | 1095 | int ls_main(int argc UNUSED_PARAM, char **argv) |
1057 | { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */ | 1096 | { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */ |
@@ -1203,6 +1242,9 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1203 | dn = NULL; | 1242 | dn = NULL; |
1204 | nfiles = 0; | 1243 | nfiles = 0; |
1205 | do { | 1244 | do { |
1245 | #if ENABLE_PLATFORM_MINGW32 | ||
1246 | *argv = fix_backslash(*argv); | ||
1247 | #endif | ||
1206 | cur = my_stat(*argv, *argv, | 1248 | cur = my_stat(*argv, *argv, |
1207 | /* follow links on command line unless -l, -i, -s or -F: */ | 1249 | /* follow links on command line unless -l, -i, -s or -F: */ |
1208 | !(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F)) | 1250 | !(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F)) |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index d5bd7bfe8..76ee5137a 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 a20fc3301..aabc51e0d 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -151,10 +151,21 @@ static double my_xstrtod(const char *arg) | |||
151 | return result; | 151 | return result; |
152 | } | 152 | } |
153 | 153 | ||
154 | static int fputs_stdout(const char *s) | ||
155 | { | ||
156 | return fputs(s, stdout); | ||
157 | } | ||
158 | |||
154 | /* Handles %b; return 1 if output is to be short-circuited by \c */ | 159 | /* Handles %b; return 1 if output is to be short-circuited by \c */ |
155 | static int print_esc_string(const char *str) | 160 | static int print_esc_string(const char *str) |
156 | { | 161 | { |
157 | char c; | 162 | char c; |
163 | #if ENABLE_PLATFORM_MINGW32 | ||
164 | char *s, *t; | ||
165 | int ret = 0; | ||
166 | |||
167 | s = t = xstrdup(str); | ||
168 | #endif | ||
158 | while ((c = *str) != '\0') { | 169 | while ((c = *str) != '\0') { |
159 | str++; | 170 | str++; |
160 | if (c == '\\') { | 171 | if (c == '\\') { |
@@ -166,7 +177,12 @@ static int print_esc_string(const char *str) | |||
166 | } | 177 | } |
167 | } | 178 | } |
168 | else if (*str == 'c') { | 179 | else if (*str == 'c') { |
180 | #if ENABLE_PLATFORM_MINGW32 | ||
181 | ret = 1; | ||
182 | goto finish; | ||
183 | #else | ||
169 | return 1; | 184 | return 1; |
185 | #endif | ||
170 | } | 186 | } |
171 | { | 187 | { |
172 | /* optimization: don't force arg to be on-stack, | 188 | /* optimization: don't force arg to be on-stack, |
@@ -176,10 +192,21 @@ static int print_esc_string(const char *str) | |||
176 | str = z; | 192 | str = z; |
177 | } | 193 | } |
178 | } | 194 | } |
195 | #if ENABLE_PLATFORM_MINGW32 | ||
196 | *t++ = c; | ||
197 | #else | ||
179 | putchar(c); | 198 | putchar(c); |
199 | #endif | ||
180 | } | 200 | } |
181 | 201 | #if ENABLE_PLATFORM_MINGW32 | |
202 | finish: | ||
203 | *t = '\0'; | ||
204 | fputs_stdout(s); | ||
205 | free(s); | ||
206 | return ret; | ||
207 | #else | ||
182 | return 0; | 208 | return 0; |
209 | #endif | ||
183 | } | 210 | } |
184 | 211 | ||
185 | static void print_direc(char *format, unsigned fmt_length, | 212 | static void print_direc(char *format, unsigned fmt_length, |
@@ -293,10 +320,19 @@ static char **print_formatted(char *f, char **argv, int *conv_err) | |||
293 | int field_width; /* Arg to first '*' */ | 320 | int field_width; /* Arg to first '*' */ |
294 | int precision; /* Arg to second '*' */ | 321 | int precision; /* Arg to second '*' */ |
295 | char **saved_argv = argv; | 322 | char **saved_argv = argv; |
323 | #if ENABLE_PLATFORM_MINGW32 | ||
324 | char *s, *t; | ||
325 | s = t = auto_string(xstrdup(f)); | ||
326 | #endif | ||
296 | 327 | ||
297 | for (; *f; ++f) { | 328 | for (; *f; ++f) { |
298 | switch (*f) { | 329 | switch (*f) { |
299 | case '%': | 330 | case '%': |
331 | #if ENABLE_PLATFORM_MINGW32 | ||
332 | *t = '\0'; | ||
333 | fputs_stdout(s); | ||
334 | t = s; | ||
335 | #endif | ||
300 | direc_start = f++; | 336 | direc_start = f++; |
301 | direc_length = 1; | 337 | direc_length = 1; |
302 | field_width = precision = 0; | 338 | field_width = precision = 0; |
@@ -385,6 +421,27 @@ static char **print_formatted(char *f, char **argv, int *conv_err) | |||
385 | free(p); | 421 | free(p); |
386 | } | 422 | } |
387 | break; | 423 | break; |
424 | #if ENABLE_PLATFORM_MINGW32 | ||
425 | case '\\': | ||
426 | if (*++f == 'c') { | ||
427 | *t = '\0'; | ||
428 | fputs_stdout(s); | ||
429 | return saved_argv; /* causes main() to exit */ | ||
430 | } | ||
431 | *t = bb_process_escape_sequence((const char **)&f); | ||
432 | if (*t == '\0') { | ||
433 | fputs_stdout(s); | ||
434 | bb_putchar(*t); | ||
435 | t = s; | ||
436 | } | ||
437 | else { | ||
438 | ++t; | ||
439 | } | ||
440 | f--; | ||
441 | break; | ||
442 | default: | ||
443 | *t++ = *f; | ||
444 | #else | ||
388 | case '\\': | 445 | case '\\': |
389 | if (*++f == 'c') { | 446 | if (*++f == 'c') { |
390 | return saved_argv; /* causes main() to exit */ | 447 | return saved_argv; /* causes main() to exit */ |
@@ -394,8 +451,13 @@ static char **print_formatted(char *f, char **argv, int *conv_err) | |||
394 | break; | 451 | break; |
395 | default: | 452 | default: |
396 | putchar(*f); | 453 | putchar(*f); |
454 | #endif | ||
397 | } | 455 | } |
398 | } | 456 | } |
457 | #if ENABLE_PLATFORM_MINGW32 | ||
458 | *t = '\0'; | ||
459 | fputs_stdout(s); | ||
460 | #endif | ||
399 | 461 | ||
400 | return argv; | 462 | return argv; |
401 | } | 463 | } |
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 | |||
41 | int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 45 | int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
42 | int shred_main(int argc UNUSED_PARAM, char **argv) | 46 | int 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 073b2c67b..0a3f251f3 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") \ |
@@ -317,6 +318,7 @@ static void FAST_FUNC print_stat(char *pformat, const char m, | |||
317 | printfs(pformat, filename); | 318 | printfs(pformat, filename); |
318 | } else if (m == 'N') { | 319 | } else if (m == 'N') { |
319 | strcatc(pformat, 's'); | 320 | strcatc(pformat, 's'); |
321 | #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 | ||
320 | if (S_ISLNK(statbuf->st_mode)) { | 322 | if (S_ISLNK(statbuf->st_mode)) { |
321 | char *linkname = xmalloc_readlink_or_warn(filename); | 323 | char *linkname = xmalloc_readlink_or_warn(filename); |
322 | if (linkname == NULL) | 324 | if (linkname == NULL) |
@@ -326,6 +328,9 @@ static void FAST_FUNC print_stat(char *pformat, const char m, | |||
326 | } else { | 328 | } else { |
327 | printf(pformat, filename); | 329 | printf(pformat, filename); |
328 | } | 330 | } |
331 | #else | ||
332 | printf(pformat, filename); | ||
333 | #endif | ||
329 | } else if (m == 'd') { | 334 | } else if (m == 'd') { |
330 | strcat(pformat, "llu"); | 335 | strcat(pformat, "llu"); |
331 | printf(pformat, (unsigned long long) statbuf->st_dev); | 336 | printf(pformat, (unsigned long long) statbuf->st_dev); |
@@ -709,6 +714,7 @@ static bool do_stat(const char *filename, const char *format) | |||
709 | gw_ent = getgrgid(statbuf.st_gid); | 714 | gw_ent = getgrgid(statbuf.st_gid); |
710 | pw_ent = getpwuid(statbuf.st_uid); | 715 | pw_ent = getpwuid(statbuf.st_uid); |
711 | 716 | ||
717 | #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 | ||
712 | if (S_ISLNK(statbuf.st_mode)) | 718 | if (S_ISLNK(statbuf.st_mode)) |
713 | linkname = xmalloc_readlink_or_warn(filename); | 719 | linkname = xmalloc_readlink_or_warn(filename); |
714 | if (linkname) { | 720 | if (linkname) { |
@@ -717,6 +723,9 @@ static bool do_stat(const char *filename, const char *format) | |||
717 | } else { | 723 | } else { |
718 | printf(" File: '%s'\n", filename); | 724 | printf(" File: '%s'\n", filename); |
719 | } | 725 | } |
726 | #else | ||
727 | printf(" File: '%s'\n", filename); | ||
728 | #endif | ||
720 | 729 | ||
721 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" | 730 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" |
722 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", | 731 | "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 8485e1e7d..204a7ab92 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 | ||
50 | HANDLE child = INVALID_HANDLE_VALUE; | ||
51 | |||
52 | static void kill_child(void) | ||
53 | { | ||
54 | if (child != INVALID_HANDLE_VALUE) { | ||
55 | kill_SIGTERM_by_handle(child); | ||
56 | } | ||
57 | } | ||
58 | #endif | ||
59 | |||
49 | int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 60 | int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
50 | int timeout_main(int argc UNUSED_PARAM, char **argv) | 61 | int 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,33 @@ 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 | argv += optind; | ||
159 | if ((ret=mingw_spawn_proc((const char **)argv)) == -1) { | ||
160 | xfunc_error_retval = errno == EACCES ? 126 : 127; | ||
161 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); | ||
162 | } | ||
163 | |||
164 | child = (HANDLE)ret; | ||
165 | atexit(kill_child); | ||
166 | while (1) { | ||
167 | sleep(1); | ||
168 | if (signo && --timeout <= 0) { | ||
169 | status = signo == SIGKILL ? 137 : 124; | ||
170 | break; | ||
171 | } | ||
172 | if (WaitForSingleObject(child, 0) == WAIT_OBJECT_0) { | ||
173 | /* process is gone */ | ||
174 | GetExitCodeProcess(child, &status); | ||
175 | goto finish; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | pid = (pid_t)GetProcessId(child); | ||
180 | kill(pid, signo); | ||
181 | finish: | ||
182 | CloseHandle(child); | ||
183 | child = INVALID_HANDLE_VALUE; | ||
184 | return status; | ||
185 | #endif | ||
132 | } | 186 | } |
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); |