ref: 17c753b3afc975b1e710c7f5c150f01e5f283b3c
dir: /unix/test.c/
#include <assert.h> #include <err.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "otf.h" #include "otfsys.h" #include "argbegin.h" static int otfdiscard(void *aux, const void *src, int sz) { USED(aux); USED(src); return sz; } #include "test.h" static int otfseek(void *aux, int off, int whence) { if(fseek(aux, off, whence) < 0) return -1; return ftell(aux); } static int otfread(void *aux, void *dst, int sz) { return fread(dst, 1, sz, aux); } static int otfwrite(void *aux, const void *src, int sz) { return fwrite(src, 1, sz, aux); } static void usage(Otfile *out) { printusage(out); exit(1); } int main(int argc, char **argv) { char buf[16]; Otfile in, out; out.print = (void*)fprintf; out.write = otfwrite; out.aux = fdopen(1, "wb"); in.seek = otfseek; in.read = otfread; parseoptions(); if(readlink("/proc/self/fd/1", buf, sizeof(buf)) == 9 && strcmp(buf, "/dev/null") == 0) out.write = otfdiscard; if((in.aux = fopen(*argv, "rb")) == NULL) err(1, nil); if(process(&in, &out) != 0) errx(1, "%s", otferrstr()); fclose(out.aux); return 0; }