<commit_before>/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdio.h>
#include <string.h>

#include "../util.h"

#if defined(__linux__)
	#include <sys/sysinfo.h>

	const char *
	uptime(void)
	{
		int h;
		int m;
		int uptime = 0;
		struct sysinfo info;

		sysinfo(&info);
		uptime = info.uptime;

		h = uptime / 3600;
		m = (uptime - h * 3600) / 60;

		return bprintf("%dh %dm", h, m);
	}
#elif defined(__OpenBSD__)
	#include <sys/sysctl.h>
	#include <sys/time.h>

	const char *
	uptime(void)
	{
		int h;
		int m;
		int uptime = 0;

		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<commit_msg>uptime: Simplifiy and clean up<commit_after>/* See LICENSE file for copyright and license details. */
#include <stdio.h>

#include "../util.h"

const char *
format(int uptime)
{
	int h, m;

	h = uptime / 3600;
	m = (uptime - h * 3600) / 60;

	return bprintf("%dh %dm", h, m);
}

#if defined(__linux__)
	#include <sys/sysinfo.h>

	const char *
	uptime(void)
	{
		int uptime;
		struct sysinfo info;

		sysinfo(&info);
		uptime = info.uptime;

		return format(uptime);
	}
#elif defined(__OpenBSD__)
	#include <errno.h>
	#include <string.h>
	#include <sys/sysctl.h>
	#include <sys/time.h>

	const char *
	uptime(void)
	{
		int mib[2], uptime;
		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)
			fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno));
			return NULL;
		}

		uptime = now - boottime.tv_sec;

		return format(uptime);
	}
#endif
{'fraction_non_alphanumeric': 0.16110019646365423, 'fraction_numerical': 0.021611001964636542, 'mean_word_length': 3.2261410788381744, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7205644', 'n_tokens_mistral': 967, 'n_tokens_neox': 847, 'n_words': 219}