blob: 3d9fa3ee17a1eaeebf7ea02e00e31e34721f3b02 (
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
35
36
37
38
|
#include <u.h>
#include <libc.h>
#include <draw.h>
Font*
openfont(Display *d, char *name)
{
Font *fnt;
int fd, i, n;
char *buf;
Dir *dir;
fd = open(name, OREAD);
if(fd < 0)
return 0;
dir = dirfstat(fd);
if(dir == nil){
Err0:
close(fd);
return 0;
}
n = dir->length;
free(dir);
buf = malloc(n+1);
if(buf == 0)
goto Err0;
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;
}
|