diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/df.c | 33 | ||||
-rw-r--r-- | coreutils/expr.c | 4 | ||||
-rw-r--r-- | coreutils/stty.c | 148 | ||||
-rw-r--r-- | coreutils/truncate.c | 6 |
4 files changed, 180 insertions, 11 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index 03aa78148..01c41db38 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -64,7 +64,9 @@ | |||
64 | //usage: "[-Pk" | 64 | //usage: "[-Pk" |
65 | //usage: IF_FEATURE_HUMAN_READABLE("mh") | 65 | //usage: IF_FEATURE_HUMAN_READABLE("mh") |
66 | //usage: "T" | 66 | //usage: "T" |
67 | //usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE") | 67 | //usage: IF_FEATURE_DF_FANCY("a" |
68 | //usage: IF_PLATFORM_POSIX("i") | ||
69 | //usage: "] [-B SIZE") | ||
68 | //usage: "] [-t TYPE] [FILESYSTEM]..." | 70 | //usage: "] [-t TYPE] [FILESYSTEM]..." |
69 | //usage:#define df_full_usage "\n\n" | 71 | //usage:#define df_full_usage "\n\n" |
70 | //usage: "Print filesystem usage statistics\n" | 72 | //usage: "Print filesystem usage statistics\n" |
@@ -78,7 +80,9 @@ | |||
78 | //usage: "\n -t TYPE Print only mounts of this type" | 80 | //usage: "\n -t TYPE Print only mounts of this type" |
79 | //usage: IF_FEATURE_DF_FANCY( | 81 | //usage: IF_FEATURE_DF_FANCY( |
80 | //usage: "\n -a Show all filesystems" | 82 | //usage: "\n -a Show all filesystems" |
83 | //usage: IF_PLATFORM_POSIX( | ||
81 | //usage: "\n -i Inodes" | 84 | //usage: "\n -i Inodes" |
85 | //usage: ) | ||
82 | //usage: "\n -B SIZE Blocksize" | 86 | //usage: "\n -B SIZE Blocksize" |
83 | //usage: ) | 87 | //usage: ) |
84 | //usage: | 88 | //usage: |
@@ -109,6 +113,12 @@ static unsigned long kscale(unsigned long b, unsigned long bs) | |||
109 | } | 113 | } |
110 | #endif | 114 | #endif |
111 | 115 | ||
116 | #if ENABLE_PLATFORM_MINGW32 | ||
117 | # define ENABLE_FEATURE_DF_FANCY_POSIX 0 | ||
118 | #else | ||
119 | # define ENABLE_FEATURE_DF_FANCY_POSIX ENABLE_FEATURE_DF_FANCY | ||
120 | #endif | ||
121 | |||
112 | int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 122 | int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
113 | int df_main(int argc UNUSED_PARAM, char **argv) | 123 | int df_main(int argc UNUSED_PARAM, char **argv) |
114 | { | 124 | { |
@@ -124,11 +134,11 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
124 | OPT_FSTYPE = (1 << 2), | 134 | OPT_FSTYPE = (1 << 2), |
125 | OPT_t = (1 << 3), | 135 | OPT_t = (1 << 3), |
126 | OPT_ALL = (1 << 4) * ENABLE_FEATURE_DF_FANCY, | 136 | OPT_ALL = (1 << 4) * ENABLE_FEATURE_DF_FANCY, |
127 | OPT_INODE = (1 << 5) * ENABLE_FEATURE_DF_FANCY, | 137 | OPT_INODE = (1 << 5) * ENABLE_FEATURE_DF_FANCY_POSIX, |
128 | OPT_BSIZE = (1 << 6) * ENABLE_FEATURE_DF_FANCY, | 138 | OPT_BSIZE = (1 << (5 + ENABLE_FEATURE_DF_FANCY_POSIX)) * ENABLE_FEATURE_DF_FANCY, |
129 | OPT_HUMAN = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, | 139 | OPT_HUMAN = (1 << (4 + 2*ENABLE_FEATURE_DF_FANCY + ENABLE_FEATURE_DF_FANCY_POSIX)) * ENABLE_FEATURE_HUMAN_READABLE, |
130 | OPT_HUMANDEC = (1 << (5 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, | 140 | OPT_HUMANDEC = (1 << (5 + 2*ENABLE_FEATURE_DF_FANCY + ENABLE_FEATURE_DF_FANCY_POSIX)) * ENABLE_FEATURE_HUMAN_READABLE, |
131 | OPT_MEGA = (1 << (6 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, | 141 | OPT_MEGA = (1 << (6 + 2*ENABLE_FEATURE_DF_FANCY + ENABLE_FEATURE_DF_FANCY_POSIX)) * ENABLE_FEATURE_HUMAN_READABLE, |
132 | }; | 142 | }; |
133 | const char *disp_units_hdr = NULL; | 143 | const char *disp_units_hdr = NULL; |
134 | char *chp, *opt_t; | 144 | char *chp, *opt_t; |
@@ -144,7 +154,11 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
144 | 154 | ||
145 | opt = getopt32(argv, "^" | 155 | opt = getopt32(argv, "^" |
146 | "kPTt:" | 156 | "kPTt:" |
157 | #if ENABLE_PLATFORM_POSIX | ||
147 | IF_FEATURE_DF_FANCY("aiB:") | 158 | IF_FEATURE_DF_FANCY("aiB:") |
159 | #else | ||
160 | IF_FEATURE_DF_FANCY("aB:") | ||
161 | #endif | ||
148 | IF_FEATURE_HUMAN_READABLE("hHm") | 162 | IF_FEATURE_HUMAN_READABLE("hHm") |
149 | "\0" | 163 | "\0" |
150 | #if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY | 164 | #if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY |
@@ -155,6 +169,9 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
155 | , &opt_t | 169 | , &opt_t |
156 | IF_FEATURE_DF_FANCY(, &chp) | 170 | IF_FEATURE_DF_FANCY(, &chp) |
157 | ); | 171 | ); |
172 | /* -k overrides $POSIXLY_CORRECT: */ | ||
173 | if (opt & OPT_KILO) | ||
174 | df_disp_hr = 1024; | ||
158 | if (opt & OPT_MEGA) | 175 | if (opt & OPT_MEGA) |
159 | df_disp_hr = 1024*1024; | 176 | df_disp_hr = 1024*1024; |
160 | 177 | ||
@@ -185,8 +202,8 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
185 | if (disp_units_hdr == NULL) { | 202 | if (disp_units_hdr == NULL) { |
186 | #if ENABLE_FEATURE_HUMAN_READABLE | 203 | #if ENABLE_FEATURE_HUMAN_READABLE |
187 | disp_units_hdr = xasprintf("%s-blocks", | 204 | disp_units_hdr = xasprintf("%s-blocks", |
188 | /* print df_disp_hr, show no fractionals, | 205 | /* print df_disp_hr; show no fractionals; |
189 | * use suffixes if OPT_POSIX is set in opt */ | 206 | * if -P, unit=1 (print it in full, no KMG suffixes) */ |
190 | make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX)) | 207 | make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX)) |
191 | ); | 208 | ); |
192 | #else | 209 | #else |
diff --git a/coreutils/expr.c b/coreutils/expr.c index 3f7e21871..c00559e4c 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c | |||
@@ -97,6 +97,10 @@ typedef long arith_t; | |||
97 | 97 | ||
98 | /* TODO: use bb_strtol[l]? It's easier to check for errors... */ | 98 | /* TODO: use bb_strtol[l]? It's easier to check for errors... */ |
99 | 99 | ||
100 | #if ENABLE_PLATFORM_MINGW32 | ||
101 | # define STRING BB_STRING | ||
102 | #endif | ||
103 | |||
100 | /* The kinds of value we can have. */ | 104 | /* The kinds of value we can have. */ |
101 | enum { | 105 | enum { |
102 | INTEGER, | 106 | INTEGER, |
diff --git a/coreutils/stty.c b/coreutils/stty.c index c88ef07f4..92d5838c0 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -20,14 +20,30 @@ | |||
20 | //kbuild:lib-$(CONFIG_STTY) += stty.o | 20 | //kbuild:lib-$(CONFIG_STTY) += stty.o |
21 | 21 | ||
22 | //usage:#define stty_trivial_usage | 22 | //usage:#define stty_trivial_usage |
23 | //usage: IF_NOT_PLATFORM_MINGW32( | ||
23 | //usage: "[-a|g] [-F DEVICE] [SETTING]..." | 24 | //usage: "[-a|g] [-F DEVICE] [SETTING]..." |
25 | //usage: ) | ||
26 | //usage: IF_PLATFORM_MINGW32( | ||
27 | //usage: "[-a] [SETTING]..." | ||
28 | //usage: ) | ||
24 | //usage:#define stty_full_usage "\n\n" | 29 | //usage:#define stty_full_usage "\n\n" |
30 | //usage: IF_NOT_PLATFORM_MINGW32( | ||
25 | //usage: "Without arguments, prints baud rate, line discipline,\n" | 31 | //usage: "Without arguments, prints baud rate, line discipline,\n" |
26 | //usage: "and deviations from stty sane\n" | 32 | //usage: "and deviations from stty sane\n" |
27 | //usage: "\n -F DEVICE Open device instead of stdin" | 33 | //usage: "\n -F DEVICE Open device instead of stdin" |
34 | //usage: ) | ||
35 | //usage: IF_PLATFORM_MINGW32( | ||
36 | //usage: "Without arguments, prints deviations from stty sane\n" | ||
37 | //usage: ) | ||
28 | //usage: "\n -a Print all current settings in human-readable form" | 38 | //usage: "\n -a Print all current settings in human-readable form" |
39 | //usage: IF_NOT_PLATFORM_MINGW32( | ||
29 | //usage: "\n -g Print in stty-readable form" | 40 | //usage: "\n -g Print in stty-readable form" |
30 | //usage: "\n [SETTING] See manpage" | 41 | //usage: "\n [SETTING] See manpage" |
42 | //usage: ) | ||
43 | //usage: IF_PLATFORM_MINGW32( | ||
44 | //usage: "\n [SETTING] [-]echo [-]cooked [-]raw sane" | ||
45 | //usage: "\n cols N rows N size" | ||
46 | //usage: ) | ||
31 | 47 | ||
32 | /* If no args are given, write to stdout the baud rate and settings that | 48 | /* If no args are given, write to stdout the baud rate and settings that |
33 | * have been changed from their defaults. Mode reading and changes | 49 | * have been changed from their defaults. Mode reading and changes |
@@ -294,6 +310,7 @@ struct mode_info { | |||
294 | const tcflag_t bits; /* Bits to set for this mode */ | 310 | const tcflag_t bits; /* Bits to set for this mode */ |
295 | }; | 311 | }; |
296 | 312 | ||
313 | #if !ENABLE_PLATFORM_MINGW32 | ||
297 | enum { | 314 | enum { |
298 | /* Must match mode_name[] and mode_info[] order! */ | 315 | /* Must match mode_name[] and mode_info[] order! */ |
299 | IDX_evenp = 0, | 316 | IDX_evenp = 0, |
@@ -320,19 +337,30 @@ enum { | |||
320 | IDX_LCASE, | 337 | IDX_LCASE, |
321 | #endif | 338 | #endif |
322 | }; | 339 | }; |
340 | #else | ||
341 | enum { | ||
342 | /* Must match mode_name[] and mode_info[] order! */ | ||
343 | IDX_sane = 0, | ||
344 | IDX_cooked, | ||
345 | IDX_raw, | ||
346 | }; | ||
347 | #endif | ||
323 | 348 | ||
324 | #define MI_ENTRY(N,T,F,B,M) N "\0" | 349 | #define MI_ENTRY(N,T,F,B,M) N "\0" |
325 | 350 | ||
326 | /* Mode names given on command line */ | 351 | /* Mode names given on command line */ |
327 | static const char mode_name[] ALIGN1 = | 352 | static const char mode_name[] ALIGN1 = |
353 | #if !ENABLE_PLATFORM_MINGW32 | ||
328 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) | 354 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) |
329 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) | 355 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) |
330 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) | 356 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) |
331 | MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) | 357 | MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) |
332 | MI_ENTRY("ek", combination, OMIT, 0, 0 ) | 358 | MI_ENTRY("ek", combination, OMIT, 0, 0 ) |
359 | #endif | ||
333 | MI_ENTRY("sane", combination, OMIT, 0, 0 ) | 360 | MI_ENTRY("sane", combination, OMIT, 0, 0 ) |
334 | MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) | 361 | MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) |
335 | MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) | 362 | MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) |
363 | #if !ENABLE_PLATFORM_MINGW32 | ||
336 | MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) | 364 | MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) |
337 | MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) | 365 | MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) |
338 | MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) | 366 | MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) |
@@ -454,7 +482,9 @@ static const char mode_name[] ALIGN1 = | |||
454 | #if IEXTEN | 482 | #if IEXTEN |
455 | MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) | 483 | MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) |
456 | #endif | 484 | #endif |
485 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
457 | MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) | 486 | MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) |
487 | #if !ENABLE_PLATFORM_MINGW32 | ||
458 | MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) | 488 | MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) |
459 | MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 ) | 489 | MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 ) |
460 | MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) | 490 | MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) |
@@ -482,6 +512,7 @@ static const char mode_name[] ALIGN1 = | |||
482 | #ifdef EXTPROC | 512 | #ifdef EXTPROC |
483 | MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 ) | 513 | MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 ) |
484 | #endif | 514 | #endif |
515 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
485 | ; | 516 | ; |
486 | 517 | ||
487 | #undef MI_ENTRY | 518 | #undef MI_ENTRY |
@@ -489,14 +520,17 @@ static const char mode_name[] ALIGN1 = | |||
489 | 520 | ||
490 | static const struct mode_info mode_info[] ALIGN4 = { | 521 | static const struct mode_info mode_info[] ALIGN4 = { |
491 | /* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */ | 522 | /* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */ |
523 | #if !ENABLE_PLATFORM_MINGW32 | ||
492 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) | 524 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) |
493 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) | 525 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) |
494 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) | 526 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) |
495 | MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) | 527 | MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) |
496 | MI_ENTRY("ek", combination, OMIT, 0, 0 ) | 528 | MI_ENTRY("ek", combination, OMIT, 0, 0 ) |
529 | #endif | ||
497 | MI_ENTRY("sane", combination, OMIT, 0, 0 ) | 530 | MI_ENTRY("sane", combination, OMIT, 0, 0 ) |
498 | MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) | 531 | MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) |
499 | MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) | 532 | MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) |
533 | #if !ENABLE_PLATFORM_MINGW32 | ||
500 | MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) | 534 | MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) |
501 | MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) | 535 | MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) |
502 | MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) | 536 | MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) |
@@ -618,7 +652,9 @@ static const struct mode_info mode_info[] ALIGN4 = { | |||
618 | #if IEXTEN | 652 | #if IEXTEN |
619 | MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) | 653 | MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) |
620 | #endif | 654 | #endif |
655 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
621 | MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) | 656 | MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) |
657 | #if !ENABLE_PLATFORM_MINGW32 | ||
622 | MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) | 658 | MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) |
623 | MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 ) | 659 | MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 ) |
624 | MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) | 660 | MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) |
@@ -646,6 +682,7 @@ static const struct mode_info mode_info[] ALIGN4 = { | |||
646 | #ifdef EXTPROC | 682 | #ifdef EXTPROC |
647 | MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 ) | 683 | MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 ) |
648 | #endif | 684 | #endif |
685 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
649 | }; | 686 | }; |
650 | 687 | ||
651 | enum { | 688 | enum { |
@@ -653,6 +690,7 @@ enum { | |||
653 | }; | 690 | }; |
654 | 691 | ||
655 | 692 | ||
693 | #if !ENABLE_PLATFORM_MINGW32 | ||
656 | /* Control characters */ | 694 | /* Control characters */ |
657 | struct control_info { | 695 | struct control_info { |
658 | const uint8_t saneval; /* Value to set for 'stty sane' */ | 696 | const uint8_t saneval; /* Value to set for 'stty sane' */ |
@@ -786,6 +824,7 @@ static const struct control_info control_info[] ALIGN2 = { | |||
786 | enum { | 824 | enum { |
787 | NUM_control_info = ARRAY_SIZE(control_info) | 825 | NUM_control_info = ARRAY_SIZE(control_info) |
788 | }; | 826 | }; |
827 | #endif | ||
789 | 828 | ||
790 | 829 | ||
791 | struct globals { | 830 | struct globals { |
@@ -803,6 +842,7 @@ struct globals { | |||
803 | G.current_col = 0; /* we are noexec, must clear */ \ | 842 | G.current_col = 0; /* we are noexec, must clear */ \ |
804 | } while (0) | 843 | } while (0) |
805 | 844 | ||
845 | #if !ENABLE_PLATFORM_MINGW32 | ||
806 | static void set_speed_or_die(enum speed_setting type, const char *arg, | 846 | static void set_speed_or_die(enum speed_setting type, const char *arg, |
807 | struct termios *mode) | 847 | struct termios *mode) |
808 | { | 848 | { |
@@ -817,6 +857,7 @@ static void set_speed_or_die(enum speed_setting type, const char *arg, | |||
817 | cfsetospeed(mode, baud); | 857 | cfsetospeed(mode, baud); |
818 | } | 858 | } |
819 | } | 859 | } |
860 | #endif | ||
820 | 861 | ||
821 | static NORETURN void perror_on_device_and_die(const char *fmt) | 862 | static NORETURN void perror_on_device_and_die(const char *fmt) |
822 | { | 863 | { |
@@ -918,6 +959,7 @@ static const struct mode_info *find_mode(const char *name) | |||
918 | return i >= 0 ? &mode_info[i] : NULL; | 959 | return i >= 0 ? &mode_info[i] : NULL; |
919 | } | 960 | } |
920 | 961 | ||
962 | #if !ENABLE_PLATFORM_MINGW32 | ||
921 | static const struct control_info *find_control(const char *name) | 963 | static const struct control_info *find_control(const char *name) |
922 | { | 964 | { |
923 | int i = index_in_strings(control_name, name); | 965 | int i = index_in_strings(control_name, name); |
@@ -954,7 +996,32 @@ static int find_param(const char *name) | |||
954 | i |= 0x80; | 996 | i |= 0x80; |
955 | return i; | 997 | return i; |
956 | } | 998 | } |
999 | #else | ||
1000 | enum { | ||
1001 | param_need_arg = 0x80, | ||
1002 | param_rows = 1 | 0x80, | ||
1003 | param_cols = 2 | 0x80, | ||
1004 | param_columns = 3 | 0x80, | ||
1005 | param_size = 4, | ||
1006 | }; | ||
957 | 1007 | ||
1008 | static int find_param(const char *name) | ||
1009 | { | ||
1010 | static const char params[] ALIGN1 = | ||
1011 | "rows\0" /* 1 */ | ||
1012 | "cols\0" /* 2 */ | ||
1013 | "columns\0" /* 3 */ | ||
1014 | "size\0"; /* 4 */ | ||
1015 | int i = index_in_strings(params, name) + 1; | ||
1016 | if (i == 0) | ||
1017 | return 0; | ||
1018 | if (i != 4) | ||
1019 | i |= 0x80; | ||
1020 | return i; | ||
1021 | } | ||
1022 | #endif | ||
1023 | |||
1024 | #if !ENABLE_PLATFORM_MINGW32 | ||
958 | static int recover_mode(const char *arg, struct termios *mode) | 1025 | static int recover_mode(const char *arg, struct termios *mode) |
959 | { | 1026 | { |
960 | int i, n; | 1027 | int i, n; |
@@ -1013,6 +1080,9 @@ static void display_speed(const struct termios *mode, int fancy) | |||
1013 | if (fancy) fmt_str += 9; | 1080 | if (fancy) fmt_str += 9; |
1014 | wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed)); | 1081 | wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed)); |
1015 | } | 1082 | } |
1083 | #else | ||
1084 | # define display_speed(m, f) ((void)0) | ||
1085 | #endif | ||
1016 | 1086 | ||
1017 | static void do_display(const struct termios *mode, int all) | 1087 | static void do_display(const struct termios *mode, int all) |
1018 | { | 1088 | { |
@@ -1030,6 +1100,7 @@ static void do_display(const struct termios *mode, int all) | |||
1030 | newline(); | 1100 | newline(); |
1031 | #endif | 1101 | #endif |
1032 | 1102 | ||
1103 | #if !ENABLE_PLATFORM_MINGW32 | ||
1033 | for (i = 0; i != CIDX_min; ++i) { | 1104 | for (i = 0; i != CIDX_min; ++i) { |
1034 | char ch; | 1105 | char ch; |
1035 | char buf10[10]; | 1106 | char buf10[10]; |
@@ -1059,6 +1130,7 @@ static void do_display(const struct termios *mode, int all) | |||
1059 | #endif | 1130 | #endif |
1060 | wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]); | 1131 | wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]); |
1061 | newline(); | 1132 | newline(); |
1133 | #endif | ||
1062 | 1134 | ||
1063 | for (i = 0; i < NUM_mode_info; ++i) { | 1135 | for (i = 0; i < NUM_mode_info; ++i) { |
1064 | if (mode_info[i].flags & OMIT) | 1136 | if (mode_info[i].flags & OMIT) |
@@ -1086,6 +1158,7 @@ static void do_display(const struct termios *mode, int all) | |||
1086 | 1158 | ||
1087 | static void sane_mode(struct termios *mode) | 1159 | static void sane_mode(struct termios *mode) |
1088 | { | 1160 | { |
1161 | #if !ENABLE_PLATFORM_MINGW32 | ||
1089 | int i; | 1162 | int i; |
1090 | 1163 | ||
1091 | for (i = 0; i < NUM_control_info; ++i) { | 1164 | for (i = 0; i < NUM_control_info; ++i) { |
@@ -1110,6 +1183,11 @@ static void sane_mode(struct termios *mode) | |||
1110 | *bitsp = val & ~mode_info[i].bits; | 1183 | *bitsp = val & ~mode_info[i].bits; |
1111 | } | 1184 | } |
1112 | } | 1185 | } |
1186 | #else | ||
1187 | mode->c_lflag |= ECHO; | ||
1188 | mode->w_mode |= ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | | ||
1189 | ENABLE_PROCESSED_INPUT; | ||
1190 | #endif | ||
1113 | } | 1191 | } |
1114 | 1192 | ||
1115 | static void set_mode(const struct mode_info *info, int reversed, | 1193 | static void set_mode(const struct mode_info *info, int reversed, |
@@ -1129,6 +1207,7 @@ static void set_mode(const struct mode_info *info, int reversed, | |||
1129 | } | 1207 | } |
1130 | 1208 | ||
1131 | /* !bitsp - it's a "combination" mode */ | 1209 | /* !bitsp - it's a "combination" mode */ |
1210 | #if !ENABLE_PLATFORM_MINGW32 | ||
1132 | if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) { | 1211 | if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) { |
1133 | if (reversed) | 1212 | if (reversed) |
1134 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; | 1213 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; |
@@ -1150,9 +1229,14 @@ static void set_mode(const struct mode_info *info, int reversed, | |||
1150 | } else if (info == &mode_info[IDX_ek]) { | 1229 | } else if (info == &mode_info[IDX_ek]) { |
1151 | mode->c_cc[VERASE] = CERASE; | 1230 | mode->c_cc[VERASE] = CERASE; |
1152 | mode->c_cc[VKILL] = CKILL; | 1231 | mode->c_cc[VKILL] = CKILL; |
1153 | } else if (info == &mode_info[IDX_sane]) { | 1232 | } |
1233 | else | ||
1234 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
1235 | if (info == &mode_info[IDX_sane]) { | ||
1154 | sane_mode(mode); | 1236 | sane_mode(mode); |
1155 | } else if (info == &mode_info[IDX_cbreak]) { | 1237 | } |
1238 | #if !ENABLE_PLATFORM_MINGW32 | ||
1239 | else if (info == &mode_info[IDX_cbreak]) { | ||
1156 | if (reversed) | 1240 | if (reversed) |
1157 | mode->c_lflag |= ICANON; | 1241 | mode->c_lflag |= ICANON; |
1158 | else | 1242 | else |
@@ -1175,11 +1259,14 @@ static void set_mode(const struct mode_info *info, int reversed, | |||
1175 | mode->c_iflag &= ~ISTRIP; | 1259 | mode->c_iflag &= ~ISTRIP; |
1176 | mode->c_oflag &= ~OPOST; | 1260 | mode->c_oflag &= ~OPOST; |
1177 | } | 1261 | } |
1178 | } else if (info == &mode_info[IDX_raw] || info == &mode_info[IDX_cooked]) { | 1262 | } |
1263 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
1264 | else if (info == &mode_info[IDX_raw] || info == &mode_info[IDX_cooked]) { | ||
1179 | if ((info == &mode_info[IDX_raw] && reversed) | 1265 | if ((info == &mode_info[IDX_raw] && reversed) |
1180 | || (info == &mode_info[IDX_cooked] && !reversed) | 1266 | || (info == &mode_info[IDX_cooked] && !reversed) |
1181 | ) { | 1267 | ) { |
1182 | /* Cooked mode */ | 1268 | /* Cooked mode */ |
1269 | #if !ENABLE_PLATFORM_MINGW32 | ||
1183 | mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON; | 1270 | mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON; |
1184 | mode->c_oflag |= OPOST; | 1271 | mode->c_oflag |= OPOST; |
1185 | mode->c_lflag |= ISIG | ICANON; | 1272 | mode->c_lflag |= ISIG | ICANON; |
@@ -1189,15 +1276,23 @@ static void set_mode(const struct mode_info *info, int reversed, | |||
1189 | #if VTIME == VEOL | 1276 | #if VTIME == VEOL |
1190 | mode->c_cc[VEOL] = CEOL; | 1277 | mode->c_cc[VEOL] = CEOL; |
1191 | #endif | 1278 | #endif |
1279 | #else | ||
1280 | mode->w_mode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT; | ||
1281 | #endif | ||
1192 | } else { | 1282 | } else { |
1193 | /* Raw mode */ | 1283 | /* Raw mode */ |
1284 | #if !ENABLE_PLATFORM_MINGW32 | ||
1194 | mode->c_iflag = 0; | 1285 | mode->c_iflag = 0; |
1195 | mode->c_oflag &= ~OPOST; | 1286 | mode->c_oflag &= ~OPOST; |
1196 | mode->c_lflag &= ~(ISIG | ICANON | XCASE); | 1287 | mode->c_lflag &= ~(ISIG | ICANON | XCASE); |
1197 | mode->c_cc[VMIN] = 1; | 1288 | mode->c_cc[VMIN] = 1; |
1198 | mode->c_cc[VTIME] = 0; | 1289 | mode->c_cc[VTIME] = 0; |
1290 | #else | ||
1291 | mode->w_mode &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); | ||
1292 | #endif | ||
1199 | } | 1293 | } |
1200 | } | 1294 | } |
1295 | #if !ENABLE_PLATFORM_MINGW32 | ||
1201 | #if IXANY | 1296 | #if IXANY |
1202 | else if (info == &mode_info[IDX_decctlq]) { | 1297 | else if (info == &mode_info[IDX_decctlq]) { |
1203 | if (reversed) | 1298 | if (reversed) |
@@ -1244,8 +1339,10 @@ static void set_mode(const struct mode_info *info, int reversed, | |||
1244 | mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE; | 1339 | mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE; |
1245 | if (IXANY) mode->c_iflag &= ~IXANY; | 1340 | if (IXANY) mode->c_iflag &= ~IXANY; |
1246 | } | 1341 | } |
1342 | #endif /*!ENABLE_PLATFORM_MINGW32 */ | ||
1247 | } | 1343 | } |
1248 | 1344 | ||
1345 | #if !ENABLE_PLATFORM_MINGW32 | ||
1249 | static void set_control_char_or_die(const struct control_info *info, | 1346 | static void set_control_char_or_die(const struct control_info *info, |
1250 | const char *arg, struct termios *mode) | 1347 | const char *arg, struct termios *mode) |
1251 | { | 1348 | { |
@@ -1265,6 +1362,7 @@ static void set_control_char_or_die(const struct control_info *info, | |||
1265 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); | 1362 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); |
1266 | mode->c_cc[info->offset] = value; | 1363 | mode->c_cc[info->offset] = value; |
1267 | } | 1364 | } |
1365 | #endif | ||
1268 | 1366 | ||
1269 | #define STTY_require_set_attr (1 << 0) | 1367 | #define STTY_require_set_attr (1 << 0) |
1270 | #define STTY_speed_was_set (1 << 1) | 1368 | #define STTY_speed_was_set (1 << 1) |
@@ -1277,7 +1375,9 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1277 | { | 1375 | { |
1278 | struct termios mode; | 1376 | struct termios mode; |
1279 | void (*output_func)(const struct termios *, int); | 1377 | void (*output_func)(const struct termios *, int); |
1378 | #if !ENABLE_PLATFORM_MINGW32 | ||
1280 | const char *file_name = NULL; | 1379 | const char *file_name = NULL; |
1380 | #endif | ||
1281 | int display_all = 0; | 1381 | int display_all = 0; |
1282 | int stty_state; | 1382 | int stty_state; |
1283 | int k; | 1383 | int k; |
@@ -1291,7 +1391,9 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1291 | k = 0; | 1391 | k = 0; |
1292 | while (argv[++k]) { | 1392 | while (argv[++k]) { |
1293 | const struct mode_info *mp; | 1393 | const struct mode_info *mp; |
1394 | #if !ENABLE_PLATFORM_MINGW32 | ||
1294 | const struct control_info *cp; | 1395 | const struct control_info *cp; |
1396 | #endif | ||
1295 | const char *arg = argv[k]; | 1397 | const char *arg = argv[k]; |
1296 | const char *argnext = argv[k+1]; | 1398 | const char *argnext = argv[k+1]; |
1297 | int param; | 1399 | int param; |
@@ -1314,6 +1416,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1314 | output_func = do_display; | 1416 | output_func = do_display; |
1315 | display_all = 1; | 1417 | display_all = 1; |
1316 | break; | 1418 | break; |
1419 | #if !ENABLE_PLATFORM_MINGW32 | ||
1317 | case 'g': | 1420 | case 'g': |
1318 | stty_state |= STTY_recoverable_output; | 1421 | stty_state |= STTY_recoverable_output; |
1319 | output_func = display_recoverable; | 1422 | output_func = display_recoverable; |
@@ -1334,11 +1437,14 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1334 | } | 1437 | } |
1335 | } | 1438 | } |
1336 | goto end_option; | 1439 | goto end_option; |
1440 | #endif | ||
1337 | default: | 1441 | default: |
1338 | goto invalid_argument; | 1442 | goto invalid_argument; |
1339 | } | 1443 | } |
1340 | } | 1444 | } |
1445 | #if !ENABLE_PLATFORM_MINGW32 | ||
1341 | end_option: | 1446 | end_option: |
1447 | #endif | ||
1342 | continue; | 1448 | continue; |
1343 | } | 1449 | } |
1344 | 1450 | ||
@@ -1348,6 +1454,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1348 | continue; | 1454 | continue; |
1349 | } | 1455 | } |
1350 | 1456 | ||
1457 | #if !ENABLE_PLATFORM_MINGW32 | ||
1351 | cp = find_control(arg); | 1458 | cp = find_control(arg); |
1352 | if (cp) { | 1459 | if (cp) { |
1353 | if (!argnext) | 1460 | if (!argnext) |
@@ -1358,6 +1465,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1358 | ++k; | 1465 | ++k; |
1359 | continue; | 1466 | continue; |
1360 | } | 1467 | } |
1468 | #endif | ||
1361 | 1469 | ||
1362 | param = find_param(arg); | 1470 | param = find_param(arg); |
1363 | if (param & param_need_arg) { | 1471 | if (param & param_need_arg) { |
@@ -1381,7 +1489,11 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1381 | xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); | 1489 | xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); |
1382 | break; | 1490 | break; |
1383 | case param_size: | 1491 | case param_size: |
1492 | # if ENABLE_PLATFORM_MINGW32 | ||
1493 | break; | ||
1494 | # endif | ||
1384 | #endif | 1495 | #endif |
1496 | #if !ENABLE_PLATFORM_MINGW32 | ||
1385 | case param_speed: | 1497 | case param_speed: |
1386 | break; | 1498 | break; |
1387 | case param_ispeed: | 1499 | case param_ispeed: |
@@ -1392,15 +1504,19 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1392 | /* called for the side effect of xfunc death only */ | 1504 | /* called for the side effect of xfunc death only */ |
1393 | set_speed_or_die(output_speed, argnext, &mode); | 1505 | set_speed_or_die(output_speed, argnext, &mode); |
1394 | break; | 1506 | break; |
1507 | #endif | ||
1395 | default: | 1508 | default: |
1509 | #if !ENABLE_PLATFORM_MINGW32 | ||
1396 | if (recover_mode(arg, &mode) == 1) break; | 1510 | if (recover_mode(arg, &mode) == 1) break; |
1397 | if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) break; | 1511 | if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) break; |
1512 | #endif | ||
1398 | invalid_argument: | 1513 | invalid_argument: |
1399 | bb_error_msg_and_die("invalid argument '%s'", arg); | 1514 | bb_error_msg_and_die("invalid argument '%s'", arg); |
1400 | } | 1515 | } |
1401 | stty_state &= ~STTY_noargs; | 1516 | stty_state &= ~STTY_noargs; |
1402 | } | 1517 | } |
1403 | 1518 | ||
1519 | #if !ENABLE_PLATFORM_MINGW32 | ||
1404 | /* Specifying both -a and -g is an error */ | 1520 | /* Specifying both -a and -g is an error */ |
1405 | if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) == | 1521 | if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) == |
1406 | (STTY_verbose_output | STTY_recoverable_output) | 1522 | (STTY_verbose_output | STTY_recoverable_output) |
@@ -1413,13 +1529,22 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1413 | ) { | 1529 | ) { |
1414 | bb_simple_error_msg_and_die("modes may not be set when -a or -g is used"); | 1530 | bb_simple_error_msg_and_die("modes may not be set when -a or -g is used"); |
1415 | } | 1531 | } |
1532 | #else | ||
1533 | /* Specifying -a with non-options is an error */ | ||
1534 | if ((stty_state & STTY_verbose_output) && !(stty_state & STTY_noargs) | ||
1535 | ) { | ||
1536 | bb_simple_error_msg_and_die("modes may not be set when -a is used"); | ||
1537 | } | ||
1538 | #endif | ||
1416 | 1539 | ||
1540 | #if !ENABLE_PLATFORM_MINGW32 | ||
1417 | /* Now it is safe to start doing things */ | 1541 | /* Now it is safe to start doing things */ |
1418 | if (file_name) { | 1542 | if (file_name) { |
1419 | G.device_name = file_name; | 1543 | G.device_name = file_name; |
1420 | xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO); | 1544 | xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO); |
1421 | ndelay_off(STDIN_FILENO); | 1545 | ndelay_off(STDIN_FILENO); |
1422 | } | 1546 | } |
1547 | #endif | ||
1423 | 1548 | ||
1424 | /* Initialize to all zeroes so there is no risk memcmp will report a | 1549 | /* Initialize to all zeroes so there is no risk memcmp will report a |
1425 | spurious difference in an uninitialized portion of the structure */ | 1550 | spurious difference in an uninitialized portion of the structure */ |
@@ -1437,7 +1562,9 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1437 | k = 0; | 1562 | k = 0; |
1438 | while (argv[++k]) { | 1563 | while (argv[++k]) { |
1439 | const struct mode_info *mp; | 1564 | const struct mode_info *mp; |
1565 | #if !ENABLE_PLATFORM_MINGW32 | ||
1440 | const struct control_info *cp; | 1566 | const struct control_info *cp; |
1567 | #endif | ||
1441 | const char *arg = argv[k]; | 1568 | const char *arg = argv[k]; |
1442 | const char *argnext = argv[k+1]; | 1569 | const char *argnext = argv[k+1]; |
1443 | int param; | 1570 | int param; |
@@ -1459,6 +1586,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1459 | continue; | 1586 | continue; |
1460 | } | 1587 | } |
1461 | 1588 | ||
1589 | #if !ENABLE_PLATFORM_MINGW32 | ||
1462 | cp = find_control(arg); | 1590 | cp = find_control(arg); |
1463 | if (cp) { | 1591 | if (cp) { |
1464 | ++k; | 1592 | ++k; |
@@ -1466,6 +1594,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1466 | stty_state |= STTY_require_set_attr; | 1594 | stty_state |= STTY_require_set_attr; |
1467 | continue; | 1595 | continue; |
1468 | } | 1596 | } |
1597 | #endif | ||
1469 | 1598 | ||
1470 | param = find_param(arg); | 1599 | param = find_param(arg); |
1471 | if (param & param_need_arg) { | 1600 | if (param & param_need_arg) { |
@@ -1491,6 +1620,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1491 | set_window_size(xatoul_sfx(argnext, stty_suffixes), -1); | 1620 | set_window_size(xatoul_sfx(argnext, stty_suffixes), -1); |
1492 | break; | 1621 | break; |
1493 | #endif | 1622 | #endif |
1623 | #if !ENABLE_PLATFORM_MINGW32 | ||
1494 | case param_speed: | 1624 | case param_speed: |
1495 | display_speed(&mode, 0); | 1625 | display_speed(&mode, 0); |
1496 | break; | 1626 | break; |
@@ -1502,7 +1632,9 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1502 | set_speed_or_die(output_speed, argnext, &mode); | 1632 | set_speed_or_die(output_speed, argnext, &mode); |
1503 | stty_state |= (STTY_require_set_attr | STTY_speed_was_set); | 1633 | stty_state |= (STTY_require_set_attr | STTY_speed_was_set); |
1504 | break; | 1634 | break; |
1635 | #endif | ||
1505 | default: | 1636 | default: |
1637 | #if !ENABLE_PLATFORM_MINGW32 | ||
1506 | if (recover_mode(arg, &mode) == 1) | 1638 | if (recover_mode(arg, &mode) == 1) |
1507 | stty_state |= STTY_require_set_attr; | 1639 | stty_state |= STTY_require_set_attr; |
1508 | else /* true: if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) */{ | 1640 | else /* true: if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) */{ |
@@ -1510,15 +1642,24 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1510 | stty_state |= (STTY_require_set_attr | STTY_speed_was_set); | 1642 | stty_state |= (STTY_require_set_attr | STTY_speed_was_set); |
1511 | } /* else - impossible (caught in the first pass): | 1643 | } /* else - impossible (caught in the first pass): |
1512 | bb_error_msg_and_die("invalid argument '%s'", arg); */ | 1644 | bb_error_msg_and_die("invalid argument '%s'", arg); */ |
1645 | #endif | ||
1513 | } | 1646 | } |
1514 | } | 1647 | } |
1515 | 1648 | ||
1516 | if (stty_state & STTY_require_set_attr) { | 1649 | if (stty_state & STTY_require_set_attr) { |
1650 | #if !ENABLE_PLATFORM_MINGW32 | ||
1517 | struct termios new_mode; | 1651 | struct termios new_mode; |
1652 | #else | ||
1653 | if (mode.c_lflag & ECHO) | ||
1654 | mode.w_mode |= ENABLE_ECHO_INPUT; | ||
1655 | else | ||
1656 | mode.w_mode &= ~ENABLE_ECHO_INPUT; | ||
1657 | #endif | ||
1518 | 1658 | ||
1519 | if (tcsetattr(STDIN_FILENO, TCSADRAIN, &mode)) | 1659 | if (tcsetattr(STDIN_FILENO, TCSADRAIN, &mode)) |
1520 | perror_on_device_and_die("%s"); | 1660 | perror_on_device_and_die("%s"); |
1521 | 1661 | ||
1662 | #if !ENABLE_PLATFORM_MINGW32 | ||
1522 | /* POSIX (according to Zlotnick's book) tcsetattr returns zero if | 1663 | /* POSIX (according to Zlotnick's book) tcsetattr returns zero if |
1523 | it performs *any* of the requested operations. This means it | 1664 | it performs *any* of the requested operations. This means it |
1524 | can report 'success' when it has actually failed to perform | 1665 | can report 'success' when it has actually failed to perform |
@@ -1554,6 +1695,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1554 | #endif | 1695 | #endif |
1555 | perror_on_device_and_die("%s: cannot perform all requested operations"); | 1696 | perror_on_device_and_die("%s: cannot perform all requested operations"); |
1556 | } | 1697 | } |
1698 | #endif | ||
1557 | } | 1699 | } |
1558 | 1700 | ||
1559 | return EXIT_SUCCESS; | 1701 | return EXIT_SUCCESS; |
diff --git a/coreutils/truncate.c b/coreutils/truncate.c index 8826e6b4c..87a47bb09 100644 --- a/coreutils/truncate.c +++ b/coreutils/truncate.c | |||
@@ -73,6 +73,12 @@ int truncate_main(int argc UNUSED_PARAM, char **argv) | |||
73 | * do not report error, exitcode is also 0. | 73 | * do not report error, exitcode is also 0. |
74 | */ | 74 | */ |
75 | } else { | 75 | } else { |
76 | #if ENABLE_PLATFORM_MINGW32 | ||
77 | struct stat st; | ||
78 | |||
79 | if (fstat(fd, &st) == 0 && size > st.st_size) | ||
80 | make_sparse(fd, st.st_size, size); | ||
81 | #endif | ||
76 | if (ftruncate(fd, size) == -1) { | 82 | if (ftruncate(fd, size) == -1) { |
77 | bb_perror_msg("%s: truncate", *argv); | 83 | bb_perror_msg("%s: truncate", *argv); |
78 | ret = EXIT_FAILURE; | 84 | ret = EXIT_FAILURE; |