summaryrefslogtreecommitdiff
path: root/dmesg.c
diff options
context:
space:
mode:
authorEric Andersen1999-10-12 22:26:06 +0000
committerEric Andersen1999-10-12 22:26:06 +0000
commit3cf52d19581b2077480e7d2e63010baa1f5399c1 (patch)
treed91b0cb332ebc976126e36a394655dde7a15d8b1 /dmesg.c
parent2ce1edcf544ac675e6762c9861a6b918401ea716 (diff)
downloadbusybox-3cf52d19581b2077480e7d2e63010baa1f5399c1.zip
busybox-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz
More stuff...
Diffstat (limited to 'dmesg.c')
-rw-r--r--dmesg.c127
1 files changed, 65 insertions, 62 deletions
diff --git a/dmesg.c b/dmesg.c
index 9096621..64265b4 100644
--- a/dmesg.c
+++ b/dmesg.c
@@ -14,7 +14,6 @@
#include <linux/unistd.h>
#include <stdio.h>
-#include <getopt.h>
#define __NR_klog __NR_syslog
@@ -22,74 +21,78 @@
#include <sys/klog.h>
#define klog klogctl
#else
-static inline _syscall3(int,klog,int,type,char *,b,int,len)
-#endif /* __GLIBC__ */
+static inline _syscall3 (int, klog, int, type, char *, b, int, len)
+#endif /* __GLIBC__ */
-const char dmesg_usage[] = "dmesg";
-int
-dmesg_main(int argc, char * * argv)
+
+static const char dmesg_usage[] = "dmesg [-c] [-n level]\n";
+
+int dmesg_main (int argc, char **argv)
{
- char buf[4096];
- int i;
- int n;
- int c;
- int level = 0;
- int lastc;
- int cmd = 3;
+ char buf[4096];
+ int i;
+ int n;
+ int level = 0;
+ int lastc;
+ int cmd = 3;
- while ((c = getopt( argc, argv, "cn:" )) != EOF) {
- switch (c) {
- case 'c':
- cmd = 4;
- break;
- case 'n':
- cmd = 8;
- level = atoi(optarg);
- break;
- case '?':
- default:
- fprintf(stderr, "%s\n", dmesg_usage);
- exit(1);
- }
- }
- argc -= optind;
- argv += optind;
-
- if (argc > 1) {
- fprintf(stderr, "%s\n", dmesg_usage);
- exit(1);
- }
+ argc--;
+ argv++;
- if (cmd == 8) {
- n = klog( cmd, NULL, level );
- if (n < 0) {
- perror( "klog" );
- exit( 1 );
- }
- exit( 0 );
- }
+ /* Parse any options */
+ while (argc && **argv == '-') {
+ while (*++(*argv))
+ switch (**argv) {
+ case 'c':
+ cmd = 4;
+ break;
+ case 'n':
+ cmd = 8;
+ if (--argc == 0)
+ goto end;
+ level = atoi (*(++argv));
+ --argc;
+ ++argv;
+ break;
+ default:
+ goto end;
+ }
+ }
- n = klog( cmd, buf, sizeof( buf ) );
- if (n < 0) {
- perror( "klog" );
- exit( 1 );
- }
+ if (cmd == 8) {
+ n = klog (cmd, NULL, level);
+ if (n < 0) {
+ perror ("klog");
+ exit (FALSE);
+ }
+ exit (TRUE);
+ }
- lastc = '\n';
- for (i = 0; i < n; i++) {
- if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
- i++;
- while (buf[i] >= '0' && buf[i] <= '9')
- i++;
- if (buf[i] == '>')
+ n = klog (cmd, buf, sizeof (buf));
+ if (n < 0) {
+ perror ("klog");
+ exit (FALSE);
+ }
+
+ lastc = '\n';
+ for (i = 0; i < n; i++) {
+ if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
i++;
- }
- lastc = buf[i];
- putchar( lastc );
- }
- if (lastc != '\n')
- putchar( '\n' );
- return 0;
+ while (buf[i] >= '0' && buf[i] <= '9')
+ i++;
+ if (buf[i] == '>')
+ i++;
+ }
+ lastc = buf[i];
+ putchar (lastc);
+ }
+ if (lastc != '\n')
+ putchar ('\n');
+ exit (TRUE);
+
+ end:
+ fprintf (stderr, "Usage: %s\n", dmesg_usage);
+ exit (FALSE);
}