aboutsummaryrefslogtreecommitdiff
path: root/coreutils/stty.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-19 15:12:12 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-19 15:12:12 +0000
commit79deb66c357c45d2237e755efb13cc912805a9cd (patch)
treece0cba8066c160108351104568b59a8931aaf8e0 /coreutils/stty.c
parent2969c772c21cb628bb7ded1c3dfc0a5f860b7d56 (diff)
downloadbusybox-w32-79deb66c357c45d2237e755efb13cc912805a9cd.tar.gz
busybox-w32-79deb66c357c45d2237e755efb13cc912805a9cd.tar.bz2
busybox-w32-79deb66c357c45d2237e755efb13cc912805a9cd.zip
stty: fix few bugs found in testing
Diffstat (limited to 'coreutils/stty.c')
-rw-r--r--coreutils/stty.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c
index 378e03e90..80b94dbad 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -68,8 +68,8 @@
68# define CSWTCH _POSIX_VDISABLE 68# define CSWTCH _POSIX_VDISABLE
69#endif 69#endif
70 70
71/* SunOS 5.3 loses (^Z doesn't work) if `swtch' is the same as `susp'. 71/* SunOS 5.3 loses (^Z doesn't work) if 'swtch' is the same as 'susp'.
72 So the default is to disable `swtch.' */ 72 So the default is to disable 'swtch.' */
73#if defined (__sparc__) && defined (__svr4__) 73#if defined (__sparc__) && defined (__svr4__)
74# undef CSWTCH 74# undef CSWTCH
75# define CSWTCH _POSIX_VDISABLE 75# define CSWTCH _POSIX_VDISABLE
@@ -120,7 +120,7 @@ enum speed_setting {
120 input_speed, output_speed, both_speeds 120 input_speed, output_speed, both_speeds
121}; 121};
122 122
123/* Which member(s) of `struct termios' a mode uses */ 123/* Which member(s) of 'struct termios' a mode uses */
124enum { 124enum {
125 /* Do NOT change the order or values, as mode_type_flag() 125 /* Do NOT change the order or values, as mode_type_flag()
126 * depends on them */ 126 * depends on them */
@@ -150,10 +150,10 @@ static const char stty_LCASE[] = "LCASE";
150static const char stty_crt [] = "crt"; 150static const char stty_crt [] = "crt";
151static const char stty_dec [] = "dec"; 151static const char stty_dec [] = "dec";
152 152
153/* Flags for `struct mode_info' */ 153/* Flags for 'struct mode_info' */
154#define SANE_SET 1 /* Set in `sane' mode */ 154#define SANE_SET 1 /* Set in 'sane' mode */
155#define SANE_UNSET 2 /* Unset in `sane' mode */ 155#define SANE_UNSET 2 /* Unset in 'sane' mode */
156#define REV 4 /* Can be turned off by prepending `-' */ 156#define REV 4 /* Can be turned off by prepending '-' */
157#define OMIT 8 /* Don't display value */ 157#define OMIT 8 /* Don't display value */
158 158
159/* Each mode */ 159/* Each mode */
@@ -161,7 +161,7 @@ struct mode_info {
161 const char *name; /* Name given on command line */ 161 const char *name; /* Name given on command line */
162 char type; /* Which structure element to change */ 162 char type; /* Which structure element to change */
163 char flags; /* Setting and display options */ 163 char flags; /* Setting and display options */
164 unsigned short mask; /* Other bits to turn off for this mode */ 164 unsigned short mask; /* Other bits to turn off for this mode */
165 unsigned long bits; /* Bits to set for this mode */ 165 unsigned long bits; /* Bits to set for this mode */
166}; 166};
167 167
@@ -320,7 +320,7 @@ enum {
320/* Control character settings */ 320/* Control character settings */
321struct control_info { 321struct control_info {
322 const char *name; /* Name given on command line */ 322 const char *name; /* Name given on command line */
323 unsigned char saneval; /* Value to set for `stty sane' */ 323 unsigned char saneval; /* Value to set for 'stty sane' */
324 unsigned char offset; /* Offset in c_cc */ 324 unsigned char offset; /* Offset in c_cc */
325}; 325};
326 326
@@ -376,7 +376,7 @@ static int current_col;
376static const char *device_name = bb_msg_standard_input; 376static const char *device_name = bb_msg_standard_input;
377 377
378/* Return a string that is the printable representation of character CH */ 378/* Return a string that is the printable representation of character CH */
379/* Adapted from `cat' by Torbjorn Granlund */ 379/* Adapted from 'cat' by Torbjorn Granlund */
380static const char *visible(unsigned int ch) 380static const char *visible(unsigned int ch)
381{ 381{
382 static char buf[10]; 382 static char buf[10];
@@ -470,11 +470,13 @@ static void wrapf(const char *message, ...)
470 470
471 if (current_col > 0) { 471 if (current_col > 0) {
472 current_col++; 472 current_col++;
473 if (current_col + buflen >= max_col) { 473 if (buf[0] != '\n') {
474 putchar('\n'); 474 if (current_col + buflen >= max_col) {
475 current_col = 0; 475 putchar('\n');
476 } else 476 current_col = 0;
477 if (buf[0] != '\n') putchar(' '); 477 } else
478 putchar(' ');
479 }
478 } 480 }
479 fputs(buf, stdout); 481 fputs(buf, stdout);
480 current_col += buflen; 482 current_col += buflen;
@@ -484,16 +486,16 @@ static void wrapf(const char *message, ...)
484 486
485#ifdef TIOCGWINSZ 487#ifdef TIOCGWINSZ
486 488
487static int get_win_size(struct winsize *win) 489static int get_win_size(int fd, struct winsize *win)
488{ 490{
489 return ioctl(STDIN_FILENO, TIOCGWINSZ, (char *) win); 491 return ioctl(fd, TIOCGWINSZ, (char *) win);
490} 492}
491 493
492static void set_window_size(int rows, int cols) 494static void set_window_size(int rows, int cols)
493{ 495{
494 struct winsize win; 496 struct winsize win;
495 497
496 if (get_win_size(&win)) { 498 if (get_win_size(STDIN_FILENO, &win)) {
497 if (errno != EINVAL) { 499 if (errno != EINVAL) {
498 perror_on_device("%s"); 500 perror_on_device("%s");
499 return; 501 return;
@@ -538,7 +540,7 @@ static void display_window_size(int fancy)
538 const char *fmt_str = "%s\0%s: no size information for this device"; 540 const char *fmt_str = "%s\0%s: no size information for this device";
539 struct winsize win; 541 struct winsize win;
540 542
541 if (get_win_size(&win)) { 543 if (get_win_size(STDIN_FILENO, &win)) {
542 if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) { 544 if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) {
543 perror_on_device(fmt_str); 545 perror_on_device(fmt_str);
544 } 546 }
@@ -568,7 +570,7 @@ static int screen_columns(void)
568 (but it works for ptys). 570 (but it works for ptys).
569 It can also fail on any system when stdout isn't a tty. 571 It can also fail on any system when stdout isn't a tty.
570 In case of any failure, just use the default */ 572 In case of any failure, just use the default */
571 if (get_win_size(&win) == 0 && win.ws_col > 0) 573 if (get_win_size(STDOUT_FILENO, &win) == 0 && win.ws_col > 0)
572 return win.ws_col; 574 return win.ws_col;
573#endif 575#endif
574 576
@@ -704,7 +706,7 @@ int stty_main(int argc, char **argv)
704 bb_error_msg_and_die(bb_msg_requires_arg, "-F"); 706 bb_error_msg_and_die(bb_msg_requires_arg, "-F");
705 /* remove -F param from arg[vc] */ 707 /* remove -F param from arg[vc] */
706 --argc; 708 --argc;
707 while (argv[p+1]) { argv[p] = argv[p+1]; ++p; } 709 while (argv[p]) { argv[p] = argv[p+1]; ++p; }
708 } 710 }
709 goto end_option; 711 goto end_option;
710 default: 712 default:
@@ -784,8 +786,8 @@ end_option:
784 int fd, fdflags; 786 int fd, fdflags;
785 device_name = file_name; 787 device_name = file_name;
786 fd = xopen(device_name, O_RDONLY | O_NONBLOCK); 788 fd = xopen(device_name, O_RDONLY | O_NONBLOCK);
787 if (fd != 0) { 789 if (fd != STDIN_FILENO) {
788 dup2(fd, 0); 790 dup2(fd, STDIN_FILENO);
789 close(fd); 791 close(fd);
790 } 792 }
791 fdflags = fcntl(STDIN_FILENO, F_GETFL); 793 fdflags = fcntl(STDIN_FILENO, F_GETFL);
@@ -894,7 +896,7 @@ end_option:
894 896
895 /* POSIX (according to Zlotnick's book) tcsetattr returns zero if 897 /* POSIX (according to Zlotnick's book) tcsetattr returns zero if
896 it performs *any* of the requested operations. This means it 898 it performs *any* of the requested operations. This means it
897 can report `success' when it has actually failed to perform 899 can report 'success' when it has actually failed to perform
898 some proper subset of the requested operations. To detect 900 some proper subset of the requested operations. To detect
899 this partial failure, get the current terminal attributes and 901 this partial failure, get the current terminal attributes and
900 compare them to the requested ones */ 902 compare them to the requested ones */
@@ -1254,7 +1256,7 @@ static int recover_mode(const char *arg, struct termios *mode)
1254 unsigned long iflag, oflag, cflag, lflag; 1256 unsigned long iflag, oflag, cflag, lflag;
1255 1257
1256 /* Scan into temporaries since it is too much trouble to figure out 1258 /* Scan into temporaries since it is too much trouble to figure out
1257 the right format for `tcflag_t' */ 1259 the right format for 'tcflag_t' */
1258 if (sscanf(arg, "%lx:%lx:%lx:%lx%n", 1260 if (sscanf(arg, "%lx:%lx:%lx:%lx%n",
1259 &iflag, &oflag, &cflag, &lflag, &n) != 4) 1261 &iflag, &oflag, &cflag, &lflag, &n) != 4)
1260 return 0; 1262 return 0;