-/* $OpenBSD: dmesg.c,v 1.4 1997/01/15 23:41:10 millert Exp $ */
+/* $OpenBSD: dmesg.c,v 1.5 1997/03/29 20:28:20 tholo Exp $ */
/* $NetBSD: dmesg.c,v 1.8 1995/03/18 14:54:49 cgd Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: dmesg.c,v 1.4 1997/01/15 23:41:10 millert Exp $";
+static char rcsid[] = "$OpenBSD: dmesg.c,v 1.5 1997/03/29 20:28:20 tholo Exp $";
#endif
#endif /* not lint */
* The message buffer is circular; start at the read pointer, and
* go to the write pointer - 1.
*/
- p = cur.msg_bufc + cur.msg_bufx;
- ep = cur.msg_bufc + cur.msg_bufx - 1;
- for (newl = skip = 0; p != ep; ++p) {
- if (p == cur.msg_bufc + MSG_BSIZE)
+ p = ep = cur.msg_bufc + (cur.msg_bufx - 1 + MSG_BSIZE) % MSG_BSIZE;
+ newl = skip = 0;
+ do {
+ if (++p == cur.msg_bufc + MSG_BSIZE)
p = cur.msg_bufc;
ch = *p;
/* Skip "\n<.*>" syslog sequences. */
(void)putchar(buf[0]);
else
(void)printf("%s", buf);
- }
+ } while (p != ep);
if (!newl)
(void)putchar('\n');
exit(0);