ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit eaa5285d6896f669e76148d6e0646fa2d4080857
parent f4ad2b276cb7adfe20caac50cadd06ad578a6209
Author: sin <sin@2f30.org>
Date:   Mon, 12 Aug 2013 10:17:36 +0100

Rename syslog_{size,read,show} to dmesg_{size,read,show}

Diffstat:
MMakefile | 2+-
Mdmesg.c | 12++++++------
Alinux/dmesg.c | 42++++++++++++++++++++++++++++++++++++++++++
Dlinux/syslog.c | 42------------------------------------------
Aopenbsd/dmesg.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
Dopenbsd/syslog.c | 47-----------------------------------------------
Mubase.h | 8++++----
7 files changed, 100 insertions(+), 100 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,8 +5,8 @@ include config.mk HDR = util.h arg.h ubase.h LIB = \ + $(OS)/dmesg.o \ $(OS)/grabmntinfo.o \ - $(OS)/syslog.o \ $(OS)/umount.o \ util/eprintf.o \ util/estrtol.o diff --git a/dmesg.c b/dmesg.c @@ -22,18 +22,18 @@ main(int argc, char *argv[]) usage(); } ARGEND; - n = syslog_size(); + n = dmesg_size(); if (n < 0) - eprintf("syslog_size:"); + eprintf("dmesg_size:"); buf = malloc(n); if (!buf) eprintf("malloc:"); - n = syslog_read(buf, n); + n = dmesg_read(buf, n); if (n < 0) - eprintf("syslog_read:"); - n = syslog_show(STDOUT_FILENO, buf, n); + eprintf("dmesg_read:"); + n = dmesg_show(STDOUT_FILENO, buf, n); if (n < 0) - eprintf("syslog_show:"); + eprintf("dmesg_show:"); free(buf); return 0; } diff --git a/linux/dmesg.c b/linux/dmesg.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include <sys/klog.h> +#include <unistd.h> +#include <stdio.h> + +enum { + SYSLOG_ACTION_READ_ALL = 3, + SYSLOG_ACTION_SIZE_BUFFER = 10 +}; + +int +dmesg_size(void) +{ + return klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0); +} + +int +dmesg_read(void *buf, size_t n) +{ + return klogctl(SYSLOG_ACTION_READ_ALL, buf, n); +} + +int +dmesg_show(int fd, const void *buf, size_t n) +{ + int last = '\n'; + const char *p = buf; + size_t i; + + for (i = 0; i < n; ) { + if (last == '\n' && p[i] == '<') { + i += 2; + if (i + 1 < n && p[i + 1] == '>') + i++; + } else { + if (write(fd, &p[i], 1) != 1) + return -1; + } + last = p[i++]; + } + return 0; +} diff --git a/linux/syslog.c b/linux/syslog.c @@ -1,42 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <sys/klog.h> -#include <unistd.h> -#include <stdio.h> - -enum { - SYSLOG_ACTION_READ_ALL = 3, - SYSLOG_ACTION_SIZE_BUFFER = 10 -}; - -int -syslog_size(void) -{ - return klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0); -} - -int -syslog_read(void *buf, size_t n) -{ - return klogctl(SYSLOG_ACTION_READ_ALL, buf, n); -} - -int -syslog_show(int fd, const void *buf, size_t n) -{ - int last = '\n'; - const char *p = buf; - size_t i; - - for (i = 0; i < n; ) { - if (last == '\n' && p[i] == '<') { - i += 2; - if (i + 1 < n && p[i + 1] == '>') - i++; - } else { - if (write(fd, &p[i], 1) != 1) - return -1; - } - last = p[i++]; - } - return 0; -} diff --git a/openbsd/dmesg.c b/openbsd/dmesg.c @@ -0,0 +1,47 @@ +/* See LICENSE file for copyright and license details. */ +#include <sys/param.h> +#include <sys/sysctl.h> +#include <sys/msgbuf.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int +dmesg_size(void) +{ + int mib[2], msgbufsize; + size_t len; + int ret; + + mib[0] = CTL_KERN; + mib[1] = KERN_MSGBUFSIZE; + len = sizeof(msgbufsize); + ret = sysctl(mib, 2, &msgbufsize, &len, NULL, 0); + if (ret < 0) + return ret; + msgbufsize += sizeof(struct msgbuf) - 1; + return msgbufsize; +} + +int +dmesg_read(void *buf, size_t n) +{ + int mib[2]; + int ret; + + memset(buf, 0, n); + mib[0] = CTL_KERN; + mib[1] = KERN_MSGBUF; + ret = sysctl(mib, 2, buf, &n, NULL, 0); + if (ret < 0) + return ret; + memmove(buf, ((struct msgbuf *)buf)->msg_bufc, n); + return n; +} + +int +dmesg_show(int fd, const void *buf, size_t n) +{ + return write(fd, buf, n); +} diff --git a/openbsd/syslog.c b/openbsd/syslog.c @@ -1,47 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <sys/param.h> -#include <sys/sysctl.h> -#include <sys/msgbuf.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -int -syslog_size(void) -{ - int mib[2], msgbufsize; - size_t len; - int ret; - - mib[0] = CTL_KERN; - mib[1] = KERN_MSGBUFSIZE; - len = sizeof(msgbufsize); - ret = sysctl(mib, 2, &msgbufsize, &len, NULL, 0); - if (ret < 0) - return ret; - msgbufsize += sizeof(struct msgbuf) - 1; - return msgbufsize; -} - -int -syslog_read(void *buf, size_t n) -{ - int mib[2]; - int ret; - - memset(buf, 0, n); - mib[0] = CTL_KERN; - mib[1] = KERN_MSGBUF; - ret = sysctl(mib, 2, buf, &n, NULL, 0); - if (ret < 0) - return ret; - memmove(buf, ((struct msgbuf *)buf)->msg_bufc, n); - return n; -} - -int -syslog_show(int fd, const void *buf, size_t n) -{ - return write(fd, buf, n); -} diff --git a/ubase.h b/ubase.h @@ -8,10 +8,10 @@ struct mntinfo { int grabmntinfo(struct mntinfo **minfo); -/* syslog.c */ -int syslog_size(void); -int syslog_read(void *buf, size_t n); -int syslog_show(int fd, const void *buf, size_t n); +/* dmesg.c */ +int dmesg_size(void); +int dmesg_read(void *buf, size_t n); +int dmesg_show(int fd, const void *buf, size_t n); /* umount.c */ enum {