ref: f711b4426695620ce7646d3036f69275be73e59f
dir: /plan9/test.c/
#include <u.h> #include <libc.h> #include <bio.h> #include "otf.h" static int otfdiscard(void *aux, void *dst, int sz) { USED(aux, dst); return sz; } #include "test.h" static int otfseek(void *aux, int off, int whence) { return Bseek(aux, off, whence); } static int otfread(void *aux, void *dst, int sz) { return Bread(aux, dst, sz); } static int otfwrite(void *aux, void *dst, int sz) { return Bwrite(aux, dst, sz); } static void usage(Otfile *f) { printusage(f); exits("usage"); } void main(int argc, char **argv) { char buf[16]; Otfile in, out; in.seek = otfseek; in.read = otfread; out.print = (void*)Bprint; out.write = otfwrite; out.aux = Bfdopen(1, OWRITE); parseoptions(); if(fd2path(1, buf, sizeof(buf)) == 0 && strcmp(buf, "/dev/null") == 0) out.write = otfdiscard; if((in.aux = Bopen(*argv, OREAD)) == nil || process(&in, &out) != 0) sysfatal("%r"); Bterm(out.aux); exits(nil); }