bcat.c - 9base - revived minimalist port of Plan 9 userland to Unix | |
git clone git://git.suckless.org/9base | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
bcat.c (725B) | |
--- | |
1 #include <fmt.h> | |
2 #include "bio.h" | |
3 | |
4 Biobuf bout; | |
5 | |
6 void | |
7 bcat(Biobuf *b, char *name) | |
8 { | |
9 char buf[1000]; | |
10 int n; | |
11 | |
12 while((n = Bread(b, buf, sizeof buf)) > 0){ | |
13 if(Bwrite(&bout, buf, n) < 0) | |
14 fprint(2, "writing during %s: %r\n", name); | |
15 } | |
16 if(n < 0) | |
17 fprint(2, "reading %s: %r\n", name); | |
18 } | |
19 | |
20 int | |
21 main(int argc, char **argv) | |
22 { | |
23 int i; | |
24 Biobuf b, *bp; | |
25 Fmt fmt; | |
26 | |
27 Binit(&bout, 1, O_WRONLY); | |
28 Bfmtinit(&fmt, &bout); | |
29 fmtprint(&fmt, "hello, world\n"); | |
30 Bfmtflush(&fmt); | |
31 | |
32 if(argc == 1){ | |
33 Binit(&b, 0, O_RDONLY); | |
34 bcat(&b, "<stdin>"); | |
35 }else{ | |
36 for(i=1; i<argc; i++){ | |
37 if((bp = Bopen(argv[i], O_RDONLY)) == 0){ | |
38 fprint(2, "Bopen %s: %r\n", argv[i]); | |
39 continue; | |
40 } | |
41 bcat(bp, argv[i]); | |
42 Bterm(bp); | |
43 } | |
44 } | |
45 exit(0); | |
46 } |