[BusyBox] [PATCH] size optimisation for deallocvt.c

Tito farmatito at tiscali.it
Wed Jan 14 21:35:08 UTC 2004


Hi to all,
this patch reduces size of deallocvt.o from;
 text    data     bss     dec     hex filename
 196         0       0      196      c4   deallocvt_orig.o
-rw-r--r--    1 root     root         1360 Jan 11 19:20 deallocvt_orig.o

to:
text    data     bss     dec     hex filename
136         0       0      136      88   deallocvt.o
-rw-r--r--    1 root     root         1288 Jan 13 15:15 deallocvt.o

It also makes the usage message clearer ( from N to [N] )
and indirectly ( through bb_xgetlarg ) adds support
for  -h ;-) .

Please apply.

Ciao,
Tito

-------------- next part --------------
--- busybox-1.00-pre5/console-tools/deallocvt.c	2003-10-22 10:32:55.000000000 +0000
+++ busybox-1.00-pre5_new/console-tools/deallocvt.c	2004-01-13 15:15:14.000000000 +0000
@@ -34,33 +34,23 @@
 
 int deallocvt_main(int argc, char *argv[])
 {
-	int fd, num = 0;
+	/* num = 0 deallocate all unused consoles */
+	int num = 0;
 
-	if (argc > 2) {
-		bb_show_usage();
-	}
-
-	fd = get_console_fd();
-	
-	/*  num=0  deallocate all unused consoles */
-	if (argc == 1) {
-		goto disallocate_all;
-	}
-
-	num = bb_xgetlarg(argv[1], 10, 0, INT_MAX);
-	switch (num) {
-		case 0:
-			bb_error_msg("0: illegal VT number");
-			break;
+	switch(argc)
+	{
+		case 2:
+			if((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0)
+				bb_error_msg_and_die("0: illegal VT number");
+		/* Falltrough */
 		case 1:
-			bb_error_msg("VT 1 cannot be deallocated");
 			break;
 		default:
-disallocate_all:
-			if (ioctl(fd, VT_DISALLOCATE, num)) {
-				bb_perror_msg_and_die("VT_DISALLOCATE");
-			}
-			return EXIT_SUCCESS;
+			bb_show_usage();
+	}
+
+	if (ioctl( get_console_fd(), VT_DISALLOCATE, num )) {
+		bb_perror_msg_and_die("VT_DISALLOCATE");
 	}
-	return EXIT_FAILURE;
+	return EXIT_SUCCESS;
 }
--- busybox-1.00-pre5/include/usage.h	2003-12-20 07:30:34.000000000 +0000
+++ busybox-1.00-pre5_new/include/usage.h	2004-01-11 22:37:24.000000000 +0000
@@ -324,7 +324,7 @@
 	"4+0 records out\n"
 
 #define deallocvt_trivial_usage \
-	"N"
+	"[N]"
 #define deallocvt_full_usage \
 	 "Deallocate unused virtual terminal /dev/ttyN"
 


More information about the busybox mailing list