Use indentation to increase readability

Granted, this style is definitely not common, but for the short
utility-functions of this program it's just the right choice. This
provides great flexibility, such that in the long run, it will be
possible to also share code between the OS-implementations.

This also keeps the state-keeping at a minimum and makes it clearer
which functions are implemented on which OS without having to jiggle
around with too many files in the process.
This commit is contained in:
Laslo Hunhold
2018-05-01 19:01:22 +02:00
committed by Aaron Marcher
parent 42edfea89a
commit 9750a3d731
9 changed files with 556 additions and 522 deletions

View File

@ -2,62 +2,61 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#if defined(__linux__)
#include <sys/sysinfo.h>
#elif defined(__OpenBSD__)
#include <sys/sysctl.h>
#include <sys/time.h>
#endif
#include "../util.h"
#if defined(__linux__)
const char *
uptime(void)
{
int h;
int m;
int uptime = 0;
struct sysinfo info;
#include <sys/sysinfo.h>
sysinfo(&info);
uptime = info.uptime;
const char *
uptime(void)
{
int h;
int m;
int uptime = 0;
struct sysinfo info;
h = uptime / 3600;
m = (uptime - h * 3600) / 60;
sysinfo(&info);
uptime = info.uptime;
return bprintf("%dh %dm", h, m);
}
#elif defined(__OpenBSD__)
const char *
uptime(void)
{
int h;
int m;
int uptime = 0;
h = uptime / 3600;
m = (uptime - h * 3600) / 60;
int mib[2];
size_t size;
time_t now;
struct timeval boottime;
time(&now);
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
size = sizeof(boottime);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1)
uptime = now - boottime.tv_sec;
else {
fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno));
return NULL;
return bprintf("%dh %dm", h, m);
}
#elif defined(__OpenBSD__)
#include <sys/sysctl.h>
#include <sys/time.h>
h = uptime / 3600;
m = (uptime - h * 3600) / 60;
const char *
uptime(void)
{
int h;
int m;
int uptime = 0;
return bprintf("%dh %dm", h, m);
}
int mib[2];
size_t size;
time_t now;
struct timeval boottime;
time(&now);
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
size = sizeof(boottime);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1)
uptime = now - boottime.tv_sec;
else {
fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno));
return NULL;
}
h = uptime / 3600;
m = (uptime - h * 3600) / 60;
return bprintf("%dh %dm", h, m);
}
#endif