<commit_before>// Copyright 2016, <NAME>

#include "util.h"

#include "libjb/log.h"
#include "libjb/util.h"
#include "libjb/xcb.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>

xcb_gc_t xcbgc(struct XData * restrict X, char * fg, char * bg)
{
	xcb_connection_t * xc = X->xcb;
	const xcb_gc_t gc = xcb_generate_id(xc);
	const xcb_colormap_t cm = X->screen->default_colormap;
	xcb_void_cookie_t c = xcb_create_gc_checked(xc, gc, X->w,
		XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT,
		(uint32_t[]){jb_get_pixel(xc, cm, fg),
		jb_get_pixel(xc, cm, bg), X->font});
	xcb_generic_error_t * e = xcb_request_check(xc, c);
	if (jb_check(!e, "Could not create GC"))
		free(e);
	return gc;
}

#if defined(USE_BATTERY) || defined(USE_TEMP)
uint32_t sysval(const char *filename)
{
	FILE *f = fopen(filename, "r");
	if (jb_check(f, "Cannot open file"))
		return 0;
	size_t sz = 6;
	char buf[sz];
	fread(buf, 1, sz, f);
	jb_check(fclose(f) == 0, "Cannot close file");
	return atoi(buf);
}
#endif//USE_BATTERY||USE_TEMP
<commit_msg>Rewrite sysval to use read syscall.<commit_after>// Copyright 2016, <NAME>

#include "util.h"

#include "libjb/util.h"
#include "libjb/xcb.h"

#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

xcb_gc_t xcbgc(struct XData * restrict X, char * fg, char * bg)
{
	xcb_connection_t * xc = X->xcb;
	const xcb_gc_t gc = xcb_generate_id(xc);
	const xcb_colormap_t cm = X->screen->default_colormap;
	xcb_void_cookie_t c = xcb_create_gc_checked(xc, gc, X->w,
		XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT,
		(uint32_t[]){jb_get_pixel(xc, cm, fg),
		jb_get_pixel(xc, cm, bg), X->font});
	xcb_generic_error_t * e = xcb_request_check(xc, c);
	if (jb_check(!e, "Could not create GC"))
		free(e);
	return gc;
}

#if defined(USE_BATTERY) || defined(USE_TEMP)
uint32_t sysval(const char *filename)
{
#define BUF_SZ 6
	fd_t f = jb_open(filename, O_RDONLY);
	char buf[BUF_SZ];
	read(f, buf, BUF_SZ);
	jb_close(f);
	return atoi(buf);
}
#endif//USE_BATTERY||USE_TEMP

{'fraction_non_alphanumeric': 0.15576635047428858, 'fraction_numerical': 0.010484273589615577, 'mean_word_length': 5.204334365325077, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '1926168', 'n_tokens_mistral': 964, 'n_tokens_neox': 910, 'n_words': 195}