diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-02-24 03:25:26 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-02-24 03:25:26 +0100 |
commit | 5f8cacd2de0afc51a4c01a358ed087847f284dda (patch) | |
tree | 7a9463aaaeee0ce66bdba8f9247c956e12f4e1fa /sys/src | |
parent | cc77058aea9001d9db60049500c50b971df89456 (diff) |
libdraw: cleanup getsubfont()
Diffstat (limited to 'sys/src')
-rw-r--r-- | sys/src/libdraw/getsubfont.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/sys/src/libdraw/getsubfont.c b/sys/src/libdraw/getsubfont.c index 8f3b59d50..02634c466 100644 --- a/sys/src/libdraw/getsubfont.c +++ b/sys/src/libdraw/getsubfont.c @@ -9,27 +9,32 @@ Subfont* _getsubfont(Display *d, char *name) { - int fd; + int dolock, fd; Subfont *f; - fd = open(name, OREAD); - if(fd < 0){ - fprint(2, "getsubfont: can't open %s: %r\n", name); - return 0; - } /* * unlock display so i/o happens with display released, unless * user is doing his own locking, in which case this could break things. * _getsubfont is called only from string.c and stringwidth.c, * which are known to be safe to have this done. */ - if(d && d->locking == 0) + dolock = d != nil && d->locking == 0; + if(dolock) unlockdisplay(d); - f = readsubfont(d, name, fd, d && d->locking==0); - if(d && d->locking == 0) + + fd = open(name, OREAD); + if(fd < 0) { + fprint(2, "getsubfont: can't open %s: %r\n", name); + f = nil; + } else { + f = readsubfont(d, name, fd, dolock); + if(f == nil) + fprint(2, "getsubfont: can't read %s: %r\n", name); + close(fd); + } + + if(dolock) lockdisplay(d); - close(fd); - if(f == 0) - fprint(2, "_getsubfont: can't read %s: %r\n", name); + return f; } |