=================================================================== RCS file: /cvs/prex-old/usr/bin/dmesg/dmesg.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -r1.1.1.1 -r1.1.1.1.2.1 --- prex-old/usr/bin/dmesg/dmesg.c 2008/06/03 10:38:47 1.1.1.1 +++ prex-old/usr/bin/dmesg/dmesg.c 2008/08/13 17:12:34 1.1.1.1.2.1 @@ -28,11 +28,11 @@ */ #include -#include #include #include #include +#include #ifdef CMDBOX #define main(argc, argv) dmesg_main(argc, argv) @@ -46,8 +46,10 @@ int size; char *buf; - if (sys_debug(DCMD_LOGSIZE, &size) != 0) + if (sys_debug(DCMD_LOGSIZE, &size) != 0) { + fprintf(stderr, "dmesg: not supported\n"); exit(1); + } if ((buf = malloc(size)) == NULL) exit(1); @@ -62,42 +64,30 @@ } static int -print_msg(char *buf, int size) +print_msg(char *buf, int bufsize) { struct winsize ws; - int i, cnt, ignore; - int row, maxrow; + int i, row, maxrow; /* Get screen size */ maxrow = 79; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, (u_long)&ws) == 0) + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0) maxrow = (int)ws.ws_row - 1; - /* Find message start point */ - for (i = 0; i < size; i++) { - if (buf[i] == -1) - break; - } - if (i == size) - return 1; - row = 0; - ignore = 1; - for (cnt = 0; cnt < size; cnt++) { - if (buf[i] == '\n') { + for (i = 0; i < bufsize; i++) { + if (*buf == '\0') + break; + if (*buf == '\n') row++; - ignore = 0; - } - if (!ignore) /* skip first line */ - putc(buf[i], stdout); - if (++i >= size) - i = 0; + putc(*buf, stdout); if (row >= maxrow) { printf("--More-- "); getc(stdin); putchar('\n'); row = 0; } + buf++; } return 0; }