Kód:
tom@gama tom $ qpkg -f /bin/dmesg 
sys-apps/util-linux *
util-linux-2.11z.tar.bz2 -> sys-utils -> dmesg.c

Kód:
/* dmesg.c -- Print out the contents of the kernel ring buffer
 * Created: Sat Oct  9 16:19:47 1993
 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
 * Copyright 1993 Theodore Ts'o (tytso@athena.mit.edu)
 * This program comes with ABSOLUTELY NO WARRANTY.
 * Modifications by Rick Sladkey (jrs@world.std.com)
 * Larger buffersize 3 June 1998 by Nicolai Langfeldt, based on a patch
 * by Peeter Joot.  This was also suggested by John Hudson.
 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
 * - added Native Language Support
 *
 */

#include <linux/unistd.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include "nls.h"

#if __GNU_LIBRARY__ < 5

#ifndef __alpha__
# define __NR_klogctl __NR_syslog
  static inline _syscall3&#40;int, klogctl, int, type, char *, b, int, len&#41;;
#else /* __alpha__ */
#define klogctl syslog
#endif

#else
# include <sys/klog.h>
#endif

static char *progname;

static void
usage&#40;void&#41; &#123;
	fprintf&#40;stderr,
		_&#40;"Usage&#58; %s &#91;-c&#93; &#91;-n level&#93; &#91;-s bufsize&#93;\n"&#41;, progname&#41;;
&#125;

int
main&#40;int argc, char *argv&#91;&#93;&#41; &#123;
	char *buf;
	int  bufsize = 16392;
	int  i;
	int  n;
	int  c;
	int  level = 0;
	int  lastc;
	int  cmd = 3;

	setlocale&#40;LC_ALL, ""&#41;;
	bindtextdomain&#40;PACKAGE, LOCALEDIR&#41;;
	textdomain&#40;PACKAGE&#41;;

	progname = argv&#91;0&#93;;
	while &#40;&#40;c = getopt&#40;argc, argv, "cn&#58;s&#58;"&#41;&#41; != -1&#41; &#123;
		switch &#40;c&#41; &#123;
		case 'c'&#58;
			cmd = 4;
			break;
		case 'n'&#58;
			cmd = 8;
			level = atoi&#40;optarg&#41;;
			break;
		case 's'&#58;
			bufsize = atoi&#40;optarg&#41;;
			break;
		case '?'&#58;
		default&#58;
			usage&#40;&#41;;
			exit&#40;1&#41;;
		&#125;
	&#125;
	argc -= optind;
	argv += optind;
   
	if &#40;argc > 1&#41; &#123;
		usage&#40;&#41;;
		exit&#40;1&#41;;
	&#125;

	if &#40;cmd == 8&#41; &#123;
		n = klogctl&#40;cmd, NULL, level&#41;;
		if &#40;n < 0&#41; &#123;
			perror&#40;"klogctl"&#41;;
			exit&#40;1&#41;;
		&#125;
		exit&#40;0&#41;;
	&#125;

	if &#40;bufsize < 4096&#41; bufsize = 4096;
	buf = &#40;char*&#41;malloc&#40;bufsize&#41;;
	n = klogctl&#40;cmd, buf, bufsize&#41;;
	if &#40;n < 0&#41; &#123;
		perror&#40;"klogctl"&#41;;
		exit&#40;1&#41;;
	&#125;

	lastc = '\n';
	for &#40;i = 0; i < n; i++&#41; &#123;
		if &#40;&#40;i == 0 || buf&#91;i - 1&#93; == '\n'&#41; && buf&#91;i&#93; == '<'&#41; &#123;
			i++;
			while &#40;buf&#91;i&#93; >= '0' && buf&#91;i&#93; <= '9'&#41;
				i++;
			if &#40;buf&#91;i&#93; == '>'&#41;
				i++;
		&#125;
		lastc = buf&#91;i&#93;;
		putchar&#40;lastc&#41;;
	&#125;
	if &#40;lastc != '\n'&#41;
		putchar&#40;'\n'&#41;;
	return 0;
&#125;