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