summaryrefslogtreecommitdiff
path: root/sys/src/libdraw/openfont.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libdraw/openfont.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libdraw/openfont.c')
-rwxr-xr-xsys/src/libdraw/openfont.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/sys/src/libdraw/openfont.c b/sys/src/libdraw/openfont.c
new file mode 100755
index 000000000..3d9fa3ee1
--- /dev/null
+++ b/sys/src/libdraw/openfont.c
@@ -0,0 +1,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;
+}