aboutsummaryrefslogtreecommitdiff
path: root/dmesg.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmesg.c')
-rw-r--r--dmesg.c56
1 files changed, 21 insertions, 35 deletions
diff --git a/dmesg.c b/dmesg.c
index df2bce713..961e532b0 100644
--- a/dmesg.c
+++ b/dmesg.c
@@ -44,50 +44,36 @@ static const char dmesg_usage[] = "dmesg [-c] [-n LEVEL] [-s SIZE]\n"
44 44
45int dmesg_main(int argc, char **argv) 45int dmesg_main(int argc, char **argv)
46{ 46{
47 char *buf; 47 char *buf, c;
48 int bufsize = 8196; 48 int bufsize = 8196;
49 int i; 49 int i;
50 int n; 50 int n;
51 int level = 0; 51 int level = 0;
52 int lastc; 52 int lastc;
53 int cmd = 3; 53 int cmd = 3;
54 int stopDoingThat;
55 54
56 argc--; 55 while ((c = getopt(argc, argv, "cn:s:")) != EOF) {
57 argv++; 56 switch (c) {
58 57 case 'c':
59 /* Parse any options */ 58 cmd = 4;
60 while (argc && **argv == '-') { 59 break;
61 stopDoingThat = FALSE; 60 case 'n':
62 while (stopDoingThat == FALSE && *++(*argv)) { 61 cmd = 8;
63 switch (**argv) { 62 if (optarg == NULL)
64 case 'c': 63 usage(dmesg_usage);
65 cmd = 4; 64 level = atoi(optarg);
66 break; 65 break;
67 case 'n': 66 case 's':
68 cmd = 8; 67 if (optarg == NULL)
69 if (--argc == 0) 68 usage(dmesg_usage);
70 goto end; 69 bufsize = atoi(optarg);
71 level = atoi(*(++argv)); 70 break;
72 if (--argc > 0) 71 default:
73 ++argv; 72 usage(dmesg_usage);
74 stopDoingThat = TRUE;
75 break;
76 case 's':
77 if (--argc == 0)
78 goto end;
79 bufsize = atoi(*(++argv));
80 if (--argc > 0)
81 ++argv;
82 stopDoingThat = TRUE;
83 break;
84 default:
85 goto end;
86 }
87 } 73 }
88 } 74 }
89 75
90 if (argc > 1) { 76 if (optind < argc) {
91 goto end; 77 goto end;
92 } 78 }
93 79