view nuklear_ui/font.c @ 1489:637fbc3b5063 nuklear_ui

Added code to persist config back to a file
author Michael Pavone <pavone@retrodev.com>
date Wed, 29 Nov 2017 08:41:37 -0800
parents c5c022c7aa54
children 4f6e8acd7b6a
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>

char *default_font_path(void)
{
	FILE *fc_pipe = popen("fc-match -f '%{file}'", "r");
	if (!fc_pipe) {
		return NULL;
	}
	size_t buf_size = 128;
	char *buffer = NULL;
	size_t total = 0, read = 0;
	do {
		total += read;
		buf_size *= 2;
		buffer = realloc(buffer, buf_size);
		if (!buffer) {
			return NULL;
		}
		read = fread(buffer, 1, buf_size - total, fc_pipe);
	} while (read == (buf_size - total));
	total += read;
	buffer[total] = 0;
	
	return buffer;
}