svn commit: trunk/busybox: e2fsprogs/old_e2fsprogs editors include etc...

vda at busybox.net vda at busybox.net
Wed Nov 5 13:20:59 UTC 2008


Author: vda
Date: 2008-11-05 05:20:58 -0800 (Wed, 05 Nov 2008)
New Revision: 23938

Log:
*: code shrink by adding a wrapper around very common tcsetattr(0, TCSANOW, xx) op

function                                             old     new   delta
tcsetattr_stdin_TCSANOW                                -      14     +14
set_sane_term                                        116     113      -3
top_main                                            1277    1273      -4
make_new_session                                     421     415      -6
rawmode                                              133     126      -7
reset_term                                            18      10      -8
die                                                   43      35      -8
cookmode                                              62      54      -8
vlock_main                                           425     415     -10
read_line_input                                     3165    3155     -10
bb_askpass                                           357     347     -10
fsck_minix_main                                     3079    3065     -14
getty_main                                          2375    2332     -43
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/12 up/down: 14/-131)         Total: -117 bytes



Modified:
   trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c
   trunk/busybox/editors/vi.c
   trunk/busybox/include/libbb.h
   trunk/busybox/init/init.c
   trunk/busybox/libbb/bb_askpass.c
   trunk/busybox/libbb/get_console.c
   trunk/busybox/libbb/lineedit.c
   trunk/busybox/libbb/xfuncs.c
   trunk/busybox/loginutils/getty.c
   trunk/busybox/loginutils/vlock.c
   trunk/busybox/networking/telnetd.c
   trunk/busybox/procps/top.c
   trunk/busybox/util-linux/fsck_minix.c


Changeset:
Modified: trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c
===================================================================
--- trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/e2fsprogs/old_e2fsprogs/e2fsck.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -12281,7 +12281,7 @@
 	tmp.c_lflag &= ~(ICANON | ECHO);
 	tmp.c_cc[VMIN] = 1;
 	tmp.c_cc[VTIME] = 0;
-	tcsetattr (0, TCSANOW, &tmp);
+	tcsetattr_stdin_TCSANOW(&tmp);
 #endif
 
 	if (def == 1)
@@ -12297,7 +12297,7 @@
 			break;
 		if (c == 3) {
 #ifdef HAVE_TERMIOS_H
-			tcsetattr (0, TCSANOW, &termios);
+			tcsetattr_stdin_TCSANOW(&termios);
 #endif
 			if (e2fsck_global_ctx &&
 			    e2fsck_global_ctx->flags & E2F_FLAG_SETJMP_OK) {
@@ -12323,7 +12323,7 @@
 	else
 		puts ("no\n");
 #ifdef HAVE_TERMIOS_H
-	tcsetattr (0, TCSANOW, &termios);
+	tcsetattr_stdin_TCSANOW(&termios);
 #endif
 	return def;
 }

Modified: trunk/busybox/editors/vi.c
===================================================================
--- trunk/busybox/editors/vi.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/editors/vi.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -2106,13 +2106,13 @@
 	term_vi.c_cc[VMIN] = 1;
 	term_vi.c_cc[VTIME] = 0;
 	erase_char = term_vi.c_cc[VERASE];
-	tcsetattr(0, TCSANOW, &term_vi);
+	tcsetattr_stdin_TCSANOW(&term_vi);
 }
 
 static void cookmode(void)
 {
 	fflush(stdout);
-	tcsetattr(0, TCSANOW, &term_orig);
+	tcsetattr_stdin_TCSANOW(&term_orig);
 }
 
 //----- Come here when we get a window resize signal ---------

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/include/libbb.h	2008-11-05 13:20:58 UTC (rev 23938)
@@ -1142,6 +1142,8 @@
 /* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
 int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC;
 
+int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC;
+
 /* NB: "unsigned request" is crucial! "int request" will break some arches! */
 int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
 int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;

Modified: trunk/busybox/init/init.c
===================================================================
--- trunk/busybox/init/init.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/init/init.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -261,7 +261,7 @@
 	tty.c_lflag =
 		ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
 
-	tcsetattr(STDIN_FILENO, TCSANOW, &tty);
+	tcsetattr_stdin_TCSANOW(&tty);
 }
 
 /* Open the new terminal device.

Modified: trunk/busybox/libbb/bb_askpass.c
===================================================================
--- trunk/busybox/libbb/bb_askpass.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/libbb/bb_askpass.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -37,7 +37,7 @@
 	tio = oldtio;
 	tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
 	tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
-	tcsetattr(STDIN_FILENO, TCSANOW, &tio);
+	tcsetattr_stdin_TCSANOW(&tio);
 
 	memset(&sa, 0, sizeof(sa));
 	/* sa.sa_flags = 0; - no SA_RESTART! */
@@ -70,7 +70,7 @@
 	}
 	sigaction_set(SIGINT, &oldsa);
 
-	tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
+	tcsetattr_stdin_TCSANOW(&oldtio);
 	bb_putchar('\n');
 	fflush(stdout);
 	return ret;

Modified: trunk/busybox/libbb/get_console.c
===================================================================
--- trunk/busybox/libbb/get_console.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/libbb/get_console.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -13,7 +13,6 @@
 /* From <linux/kd.h> */
 enum { KDGKBTYPE = 0x4B33 };  /* get keyboard type */
 
-
 static int open_a_console(const char *fnam)
 {
 	int fd;
@@ -37,7 +36,6 @@
  * We try several things because opening /dev/console will fail
  * if someone else used X (which does a chown on /dev/console).
  */
-
 int FAST_FUNC get_console_fd_or_die(void)
 {
 	static const char *const console_names[] = {

Modified: trunk/busybox/libbb/lineedit.c
===================================================================
--- trunk/busybox/libbb/lineedit.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/libbb/lineedit.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -1436,7 +1436,7 @@
 #define _POSIX_VDISABLE '\0'
 #endif
 	new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
-	tcsetattr(STDIN_FILENO, TCSANOW, &new_settings);
+	tcsetattr_stdin_TCSANOW(&new_settings);
 
 	/* Now initialize things */
 	previous_SIGWINCH_handler = signal(SIGWINCH, win_changed);
@@ -1860,7 +1860,7 @@
 #endif
 
 	/* restore initial_settings */
-	tcsetattr(STDIN_FILENO, TCSANOW, &initial_settings);
+	tcsetattr_stdin_TCSANOW(&initial_settings);
 	/* restore SIGWINCH handler */
 	signal(SIGWINCH, previous_SIGWINCH_handler);
 	fflush(stdout);

Modified: trunk/busybox/libbb/xfuncs.c
===================================================================
--- trunk/busybox/libbb/xfuncs.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/libbb/xfuncs.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -289,3 +289,8 @@
 
 	return ret;
 }
+
+int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp)
+{
+	return tcsetattr(STDIN_FILENO, TCSANOW, tp);
+}

Modified: trunk/busybox/loginutils/getty.c
===================================================================
--- trunk/busybox/loginutils/getty.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/loginutils/getty.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -279,7 +279,7 @@
 	 */
 #ifdef __linux__
 	/* flush input and output queues, important for modems! */
-	ioctl(0, TCFLSH, TCIOFLUSH);
+	ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
 #endif
 
 	tp->c_cflag = CS8 | HUPCL | CREAD | speed;
@@ -297,7 +297,7 @@
 		tp->c_cflag |= CRTSCTS;
 #endif
 
-	ioctl(0, TCSETS, tp);
+	tcsetattr_stdin_TCSANOW(tp);
 
 	debug("term_io 2\n");
 }
@@ -334,7 +334,7 @@
 	tp->c_iflag |= ISTRIP;          /* enable 8th-bit stripping */
 	vmin = tp->c_cc[VMIN];
 	tp->c_cc[VMIN] = 0;             /* don't block if queue empty */
-	ioctl(0, TCSETS, tp);
+	tcsetattr_stdin_TCSANOW(tp);
 
 	/*
 	 * Wait for a while, then read everything the modem has said so far and
@@ -359,7 +359,7 @@
 	/* Restore terminal settings. Errors will be dealt with later on. */
 	tp->c_iflag = iflag;
 	tp->c_cc[VMIN] = vmin;
-	ioctl(0, TCSETS, tp);
+	tcsetattr_stdin_TCSANOW(tp);
 }
 
 /* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
@@ -404,7 +404,7 @@
 
 	/* Flush pending input (esp. after parsing or switching the baud rate). */
 	sleep(1);
-	ioctl(0, TCFLSH, TCIFLUSH);
+	ioctl(0, TCFLSH, TCIFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
 
 	/* Prompt for and read a login name. */
 	logname[0] = '\0';
@@ -552,12 +552,13 @@
 	}
 #endif
 	/* Optionally enable hardware flow control */
-#ifdef  CRTSCTS
+#ifdef CRTSCTS
 	if (op->flags & F_RTSCTS)
 		tp->c_cflag |= CRTSCTS;
 #endif
 
 	/* Finally, make the new settings effective */
+	/* It's tcsetattr_stdin_TCSANOW() + error check */
 	ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty);
 }
 
@@ -689,6 +690,7 @@
 	 * by patching the SunOS kernel variable "zsadtrlow" to a larger value;
 	 * 5 seconds seems to be a good value.
 	 */
+	/* tcgetattr() + error check */
 	ioctl_or_perror_and_die(0, TCGETS, &termios, "%s: TCGETS", options.tty);
 
 #ifdef __linux__
@@ -753,7 +755,7 @@
 			baud_index = (baud_index + 1) % options.numspeed;
 			termios.c_cflag &= ~CBAUD;
 			termios.c_cflag |= options.speeds[baud_index];
-			ioctl(0, TCSETS, &termios);
+			tcsetattr_stdin_TCSANOW(&termios);
 		}
 	}
 

Modified: trunk/busybox/loginutils/vlock.c
===================================================================
--- trunk/busybox/loginutils/vlock.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/loginutils/vlock.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -87,7 +87,7 @@
 	term.c_iflag |= IGNBRK;
 	term.c_lflag &= ~ISIG;
 	term.c_lflag &= ~(ECHO | ECHOCTL);
-	tcsetattr(STDIN_FILENO, TCSANOW, &term);
+	tcsetattr_stdin_TCSANOW(&term);
 
 	do {
 		printf("Virtual console%s locked by %s.\n",
@@ -101,6 +101,6 @@
 	} while (1);
 
 	ioctl(STDIN_FILENO, VT_SETMODE, &ovtm);
-	tcsetattr(STDIN_FILENO, TCSANOW, &oterm);
+	tcsetattr_stdin_TCSANOW(&oterm);
 	fflush_stdout_and_exit(EXIT_SUCCESS);
 }

Modified: trunk/busybox/networking/telnetd.c
===================================================================
--- trunk/busybox/networking/telnetd.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/networking/telnetd.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -243,7 +243,7 @@
 	termbuf.c_iflag |= ICRNL;
 	termbuf.c_iflag &= ~IXOFF;
 	/*termbuf.c_lflag &= ~ICANON;*/
-	tcsetattr(0, TCSANOW, &termbuf);
+	tcsetattr_stdin_TCSANOW(&termbuf);
 
 	/* Uses FILE-based I/O to stdout, but does fflush(stdout),
 	 * so should be safe with vfork.

Modified: trunk/busybox/procps/top.c
===================================================================
--- trunk/busybox/procps/top.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/procps/top.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -649,7 +649,7 @@
 
 static void reset_term(void)
 {
-	tcsetattr(0, TCSANOW, &initial_settings);
+	tcsetattr_stdin_TCSANOW(&initial_settings);
 	if (ENABLE_FEATURE_CLEAN_UP) {
 		clearmems();
 #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
@@ -941,7 +941,7 @@
 	new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
 
 	bb_signals(BB_FATAL_SIGS, sig_catcher);
-	tcsetattr(0, TCSANOW, (void *) &new_settings);
+	tcsetattr_stdin_TCSANOW(&new_settings);
 #endif /* FEATURE_USE_TERMIOS */
 
 #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE

Modified: trunk/busybox/util-linux/fsck_minix.c
===================================================================
--- trunk/busybox/util-linux/fsck_minix.c	2008-11-05 12:59:32 UTC (rev 23937)
+++ trunk/busybox/util-linux/fsck_minix.c	2008-11-05 13:20:58 UTC (rev 23938)
@@ -293,7 +293,7 @@
 static void die(const char *str)
 {
 	if (termios_set)
-		tcsetattr(0, TCSANOW, &sv_termios);
+		tcsetattr_stdin_TCSANOW(&sv_termios);
 	bb_error_msg_and_die("%s", str);
 }
 
@@ -1254,7 +1254,7 @@
 		tcgetattr(0, &sv_termios);
 		tmp = sv_termios;
 		tmp.c_lflag &= ~(ICANON | ECHO);
-		tcsetattr(0, TCSANOW, &tmp);
+		tcsetattr_stdin_TCSANOW(&tmp);
 		termios_set = 1;
 	}
 
@@ -1299,7 +1299,7 @@
 		write_superblock();
 
 	if (OPT_manual)
-		tcsetattr(0, TCSANOW, &sv_termios);
+		tcsetattr_stdin_TCSANOW(&sv_termios);
 
 	if (changed)
 		retcode += 3;




More information about the busybox-cvs mailing list