Unified · Split
| @@ -2,6 +2,14 @@ · 1 unmodified line | ||
| 2 | 2 | #include <libc.h> |
| 3 | 3 | #include <bio.h> |
| 4 | 4 | #include "otf.h" |
| 5 | + | |
| 6 | +static int | |
| 7 | +otfdiscard(void *aux, void *dst, int sz) | |
| 8 | +{ | |
| 9 | + USED(aux, dst); | |
| 10 | + return sz; | |
| 11 | +} | |
| 12 | + | |
| 5 | 13 | #include "test.h" |
| 6 | 14 | |
| 7 | 15 | static int |
| @@ -32,6 +40,7 @@ usage(Otfile *f) · 24 unmodified lines | ||
| 32 | 40 | void |
| 33 | 41 | main(int argc, char **argv) |
| 34 | 42 | { |
| 43 | + char buf[16]; | |
| 35 | 44 | Otfile in, out; |
| 36 | 45 | |
| 37 | 46 | in.seek = otfseek; |
| @@ -41,6 +50,9 @@ main(int argc, char **argv) · 3 unmodified lines | ||
| 41 | 50 | out.aux = Bfdopen(1, OWRITE); |
| 42 | 51 | parseoptions(); |
| 43 | 52 | |
| 53 | + if(fd2path(1, buf, sizeof(buf)) == 0 && strcmp(buf, "/dev/null") == 0) | |
| 54 | + out.write = otfdiscard; | |
| 55 | + | |
| 44 | 56 | if((in.aux = Bopen(*argv, OREAD)) == nil || process(&in, &out) != 0) |
| 45 | 57 | sysfatal("%r"); |
| 46 | 58 | Bterm(out.aux); |
| @@ -135,7 +135,7 @@ glypherr: · 134 unmodified lines | ||
| 135 | 135 | free(g); |
| 136 | 136 | } |
| 137 | 137 | if(ppem > 0){ |
| 138 | − if(dumpmap(out, im, n) != 0) | |
| 138 | + if(out->write != otfdiscard && dumpmap(out, im, n) != 0) | |
| 139 | 139 | return -1; |
| 140 | 140 | for(i = 0; i < n; i++) |
| 141 | 141 | free(im[i].b); |
| @@ -150,7 +150,7 @@ glypherr: · 8 unmodified lines | ||
| 150 | 150 | GlyfImage im; |
| 151 | 151 | if(otfdrawglyf(o, g, ppem, gap, &im) != 0) |
| 152 | 152 | goto glypherr; |
| 153 | − if(dumpmap(out, &im, 1) != 0) | |
| 153 | + if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0) | |
| 154 | 154 | return -1; |
| 155 | 155 | free(im.b); |
| 156 | 156 | }else{ |
| @@ -4,9 +4,18 @@ · 3 unmodified lines | ||
| 4 | 4 | #include <stdio.h> |
| 5 | 5 | #include <stdlib.h> |
| 6 | 6 | #include <string.h> |
| 7 | +#include <unistd.h> | |
| 7 | 8 | #include "otf.h" |
| 8 | 9 | #include "otfsys.h" |
| 9 | 10 | #include "argbegin.h" |
| 11 | + | |
| 12 | +static int | |
| 13 | +otfdiscard(void *aux, const void *src, int sz) | |
| 14 | +{ | |
| 15 | + USED(aux); USED(src); | |
| 16 | + return sz; | |
| 17 | +} | |
| 18 | + | |
| 10 | 19 | #include "test.h" |
| 11 | 20 | |
| 12 | 21 | static int |
| @@ -39,6 +48,7 @@ usage(Otfile *out) · 26 unmodified lines | ||
| 39 | 48 | int |
| 40 | 49 | main(int argc, char **argv) |
| 41 | 50 | { |
| 51 | + char buf[16]; | |
| 42 | 52 | Otfile in, out; |
| 43 | 53 | |
| 44 | 54 | out.print = (void*)fprintf; |
| @@ -48,6 +58,9 @@ main(int argc, char **argv) · 3 unmodified lines | ||
| 48 | 58 | in.read = otfread; |
| 49 | 59 | parseoptions(); |
| 50 | 60 | |
| 61 | + if(readlink("/proc/self/fd/1", buf, sizeof(buf)) == 9 && strcmp(buf, "/dev/null") == 0) | |
| 62 | + out.write = otfdiscard; | |
| 63 | + | |
| 51 | 64 | if((in.aux = fopen(*argv, "rb")) == NULL) |
| 52 | 65 | err(1, nil); |
| 53 | 66 | if(process(&in, &out) != 0) |