diff options
author | rsc <devnull@localhost> | 2003-10-13 17:16:15 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-10-13 17:16:15 +0000 |
commit | e6f4b2e311cd461dd2d8380ba21ab113e5c8c072 (patch) | |
tree | 89b9788990578dcbc5c9f4380373c336653055e1 | |
parent | a3c5df578fea1ccd9095ec08232b2c862e875f29 (diff) | |
download | plan9port-e6f4b2e311cd461dd2d8380ba21ab113e5c8c072.tar.gz plan9port-e6f4b2e311cd461dd2d8380ba21ab113e5c8c072.tar.bz2 plan9port-e6f4b2e311cd461dd2d8380ba21ab113e5c8c072.zip |
Rewrite /lib/font/bit to $PLAN9/font when open fails.
-rw-r--r-- | src/libdraw/openfont.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libdraw/openfont.c b/src/libdraw/openfont.c index e9fa3f84..a1ff278a 100644 --- a/src/libdraw/openfont.c +++ b/src/libdraw/openfont.c @@ -9,9 +9,27 @@ openfont(Display *d, char *name) { Font *fnt; int fd, i, n; - char *buf; + char *buf, *nambuf, *root; + nambuf = 0; fd = open(name, OREAD); + + if(fd < 0 && strncmp(name, "/lib/font/bit/", 14) == 0){ + root = getenv("PLAN9"); + if(root == nil) + return 0; + nambuf = malloc(strlen(root)+5+strlen(name+13)+1); + if(nambuf == nil) + return 0; + strcpy(nambuf, root); + strcat(nambuf, "/font"); + strcat(nambuf, name+13); + if((fd = open(nambuf, OREAD)) < 0){ + free(nambuf); + return 0; + } + name = nambuf; + } if(fd < 0) return 0; @@ -19,6 +37,7 @@ openfont(Display *d, char *name) buf = malloc(n+1); if(buf == 0){ close(fd); + free(nambuf); return 0; } buf[n] = 0; @@ -26,9 +45,11 @@ openfont(Display *d, char *name) close(fd); if(i != n){ free(buf); + free(nambuf); return 0; } fnt = buildfont(d, buf, name); free(buf); + free(nambuf); return fnt; } |