aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/openfont.c
blob: e9fa3f849b3460c32388918c7ca23cd73d194ba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <u.h>
#include <libc.h>
#include <draw.h>

extern vlong _drawflength(int);

Font*
openfont(Display *d, char *name)
{
	Font *fnt;
	int fd, i, n;
	char *buf;

	fd = open(name, OREAD);
	if(fd < 0)
		return 0;

	n = _drawflength(fd);
	buf = malloc(n+1);
	if(buf == 0){
		close(fd);
		return 0;
	}
	buf[n] = 0;
	i = read(fd, buf, n);
	close(fd);
	if(i != n){
		free(buf);
		return 0;
	}
	fnt = buildfont(d, buf, name);
	free(buf);
	return fnt;
}