shithub: fnt

ref: 3582b9cc27bf2a83800c00b4a84873037e99642d
dir: /unix/otfsys.c/

View raw version
#include "otfsys.h"
#include <stdarg.h>
#include <time.h>

#define ERRMAX 512

static char errstr[ERRMAX];

char *
otferrstr(void)
{
	return errstr;
}

void
werrstr(char *fmt, ...)
{
	va_list a;
	char buf[ERRMAX];
	int n;

	va_start(a, fmt);
	n = vsnprintf(buf, sizeof(buf), fmt, a);
	va_end(a);
	if(n >= 2 && buf[n-2] == '%' && buf[n-1] == 'r')
		snprintf(buf+n-2, sizeof(buf)-n+2, "%s", errstr);
	snprintf(errstr, sizeof(errstr), "%s", buf);
}

char *
fmttime(long long v)
{
	static char buf[32];
	time_t t = v;
	struct tm *tm;

	buf[0] = 0;
	if((tm = gmtime(&t)) != nil)
		strftime(buf, sizeof(buf), "%c", tm);
	return buf;
}