1 #include "lib9.h" 2 #include "kernel.h" 3 #include "draw.h" 4 5 Font* openfont(Display * d,char * name)6openfont(Display *d, char *name) 7 { 8 Font *fnt; 9 int fd, i, n; 10 char *buf; 11 Dir *dir; 12 13 fd = libopen(name, OREAD); 14 if(fd < 0) 15 return 0; 16 17 if((dir = libdirfstat(fd)) == nil){ 18 Err0: 19 libclose(fd); 20 return 0; 21 } 22 n = dir->length; 23 free(dir); 24 buf = malloc(n+1); 25 if(buf == 0) 26 goto Err0; 27 buf[n] = 0; 28 i = libreadn(fd, buf, n); 29 libclose(fd); 30 if(i != n){ 31 free(buf); 32 return 0; 33 } 34 fnt = buildfont(d, buf, name); 35 free(buf); 36 return fnt; 37 } 38