aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/openfont.c
blob: dc16e379b744c75f93ae55af57276e668c5fa783 (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
#include <u.h>
#include <libc.h>
#include <draw.h>

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

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

	n = flength(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;
}