History

don't dumpmap if redirected to /dev/null

Sigrid Solveig Haflínudóttir committed 2 years ago

Commit 95df0a41 parent 6b622e93 files · +27 −2Browse files

Unified · Split

3 files
  1. plan9/test.c +12 −0
  2. test.h +2 −2
  3. unix/test.c +13 −0
plan9/test.c+12−0
@@ -2,6 +2,14 @@ · 1 unmodified line
22 #include <libc.h>
33 #include <bio.h>
44 #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+
513 #include "test.h"
614
715 static int
@@ -32,6 +40,7 @@ usage(Otfile *f) · 24 unmodified lines
3240 void
3341 main(int argc, char **argv)
3442 {
43+ char buf[16];
3544 Otfile in, out;
3645
3746 in.seek = otfseek;
@@ -41,6 +50,9 @@ main(int argc, char **argv) · 3 unmodified lines
4150 out.aux = Bfdopen(1, OWRITE);
4251 parseoptions();
4352
53+ if(fd2path(1, buf, sizeof(buf)) == 0 && strcmp(buf, "/dev/null") == 0)
54+ out.write = otfdiscard;
55+
4456 if((in.aux = Bopen(*argv, OREAD)) == nil || process(&in, &out) != 0)
4557 sysfatal("%r");
4658 Bterm(out.aux);
test.h+2−2
@@ -135,7 +135,7 @@ glypherr: · 134 unmodified lines
135135 free(g);
136136 }
137137 if(ppem > 0){
138− if(dumpmap(out, im, n) != 0)
138+ if(out->write != otfdiscard && dumpmap(out, im, n) != 0)
139139 return -1;
140140 for(i = 0; i < n; i++)
141141 free(im[i].b);
@@ -150,7 +150,7 @@ glypherr: · 8 unmodified lines
150150 GlyfImage im;
151151 if(otfdrawglyf(o, g, ppem, gap, &im) != 0)
152152 goto glypherr;
153− if(dumpmap(out, &im, 1) != 0)
153+ if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0)
154154 return -1;
155155 free(im.b);
156156 }else{
unix/test.c+13−0
@@ -4,9 +4,18 @@ · 3 unmodified lines
44 #include <stdio.h>
55 #include <stdlib.h>
66 #include <string.h>
7+#include <unistd.h>
78 #include "otf.h"
89 #include "otfsys.h"
910 #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+
1019 #include "test.h"
1120
1221 static int
@@ -39,6 +48,7 @@ usage(Otfile *out) · 26 unmodified lines
3948 int
4049 main(int argc, char **argv)
4150 {
51+ char buf[16];
4252 Otfile in, out;
4353
4454 out.print = (void*)fprintf;
@@ -48,6 +58,9 @@ main(int argc, char **argv) · 3 unmodified lines
4858 in.read = otfread;
4959 parseoptions();
5060
61+ if(readlink("/proc/self/fd/1", buf, sizeof(buf)) == 9 && strcmp(buf, "/dev/null") == 0)
62+ out.write = otfdiscard;
63+
5164 if((in.aux = fopen(*argv, "rb")) == NULL)
5265 err(1, nil);
5366 if(process(&in, &out) != 0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t