svn commit: trunk/busybox/util-linux

aldot at busybox.net aldot at busybox.net
Wed Mar 29 17:26:16 UTC 2006


Author: aldot
Date: 2006-03-29 09:26:14 -0800 (Wed, 29 Mar 2006)
New Revision: 14688

Log:
- shrink dmesg a bit.
  http://busybox.net/lists/busybox/2006-March/019477.html


Modified:
   trunk/busybox/util-linux/dmesg.c


Changeset:
Modified: trunk/busybox/util-linux/dmesg.c
===================================================================
--- trunk/busybox/util-linux/dmesg.c	2006-03-29 16:52:56 UTC (rev 14687)
+++ trunk/busybox/util-linux/dmesg.c	2006-03-29 17:26:14 UTC (rev 14688)
@@ -20,7 +20,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <getopt.h>
 #include <errno.h>
 #include <sys/klog.h>
 
@@ -28,71 +27,53 @@
 
 int dmesg_main(int argc, char **argv)
 {
-	char *buf
-#ifdef CONFIG_FEATURE_CLEAN_UP
-		= NULL
-#endif
-		;
+	char *buf, *tmp;
 	int bufsize = 8196;
-	int i, n;
-	int level = 0;
-	int lastc;
-	int cmd = 3;
+	int i, n = 0;
+	int c = 3;
 
-	while ((i = getopt(argc, argv, "cn:s:")) > 0) {
-		switch (i) {
-			case 'c':
-				cmd = 4;
-				break;
-			case 'n':
-				cmd = 8;
-				level = bb_xgetlarg(optarg, 10, 0, 10);
-				break;
-			case 's':
+	i = bb_getopt_ulflags(argc, argv, "cn:s:", &buf, &tmp);
+	if (i & 1)
+				c = 4;
+	if (i & 2) {
+				c = 8;
+				n = bb_xgetlarg(buf, 10, 0, 10);
+	}
+	if (i & 4)
 				/* I think a 512k max kernel ring buffer is big enough for
 				 * anybody, as the default is 16k...  Could be wrong though.
 				 * If so I'm sure I'll hear about it by the enraged masses*/
-				bufsize = bb_xgetlarg(optarg, 10, 4096, 512*1024);
-				break;
-			default:
-				bb_show_usage();
-		}
-	}
+				bufsize = bb_xgetlarg(tmp, 10, 4096, 512*1024);
 
-	if (optind < argc) {
-		bb_show_usage();
-	}
-
-	if (cmd == 8) {
-		if (klogctl(cmd, NULL, level) < 0)
+	if (c == 8) {
+		if (klogctl(c, NULL, n) < 0)
 			goto die_the_death;
 		goto all_done;
 	}
 
 	buf = xmalloc(bufsize);
-	if ((n = klogctl(cmd, buf, bufsize)) < 0)
+	if ((n = klogctl(c, buf, bufsize)) < 0)
 		goto die_the_death;
 
-	lastc = '\n';
+	c = '\n';
 	for (i = 0; i < n; i++) {
-		if (lastc == '\n' && buf[i] == '<') {
+		if (c == '\n' && buf[i] == '<') {
 			i++;
 			while (buf[i] >= '0' && buf[i] <= '9')
 				i++;
 			if (buf[i] == '>')
 				i++;
 		}
-		lastc = buf[i];
-		putchar(lastc);
+		c = buf[i];
+		putchar(c);
 	}
-	if (lastc != '\n')
+	if (c != '\n')
 		putchar('\n');
 all_done:
-#ifdef CONFIG_FEATURE_CLEAN_UP
-	if (buf) {
+	if (ENABLE_FEATURE_CLEAN_UP) {
 		free(buf);
 	}
-#endif
+
 	return EXIT_SUCCESS;
 die_the_death:
 	bb_perror_nomsg_and_die();




More information about the busybox-cvs mailing list