Big update: 6/N fix

This commit is contained in:
Your Name 2023-11-07 17:24:49 +03:00
parent 5582a0cc18
commit 98a7ba56c7
1 changed files with 15 additions and 13 deletions

View File

@ -7,24 +7,24 @@
#include <sys/klog.h>
#define BUF_SIZE 8196
int main(const int argc, const char **argv) {
int main(int argc, char **argv) {
unsigned int s_size = 0;
unsigned int n_level = 0;
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
int opt;
while ((opt = getopt(argc, argv, "s:n:")) != -1) {
switch (opt) {
case 's':
s_size = atoi(optarg);
break;
else if (!strncmp(argv[i], "-s=", 3))
s_size = atoi(argv[i] + 3);
case 'n':
n_level = atoi(optarg);
break;
else if (!strncmp(argv[i], "-n=", 3))
n_level = atoi(argv[i] + 3);
else if (!strcmp(argv[i], "--help")) {
printf("dmesg [-n=L Set console logging level] [-s=S Buffer Size]\n");
return 0;
default:
printf("dmesg\n\t[-n=L Set console logging level] [-s=S Buffer Size]\n");
return 0;
}
}
@ -38,6 +38,7 @@ int main(const int argc, const char **argv) {
if (!s_size)
s_size = klogctl(10, NULL, 0);
/* Get kernel log */
char *buf = malloc(s_size + 1);
if (buf == NULL) {
@ -55,6 +56,7 @@ int main(const int argc, const char **argv) {
return 1;
}
/* Print */
write(STDOUT_FILENO, buf, n);
putchar('\n');