4 /* Some of the scripts in the `flaccrip' suite want to chop streams of PCM
5 * data about. Once upon a time, they used dd(1) for this, but dd does
6 * entirely the wrong thing on short reads, and short reads happen quite
9 * The requirements on this program are that it copy exactly the first N
10 * bytes from stdin to stdout, without reading anything else from stdin or
11 * writing anything else to stdout. (That's why it doesn't use stdio to do
12 * the copying: stdio buffering will read too much from stdin, which will
13 * cause stream corruption later.)
15 * As a special bonus, it's quite paranoid about error checking, and does way
16 * more work on dealing with short reads and writes than is necessary for
17 * working on pipes. It will fail miserably if either stdin or stdout is
26 #include <sys/types.h>
29 int main(int argc, char *argv[])
37 fprintf(stderr, "Usage: %s LENGTH\n", argv[0]);
40 n = strtoul(argv[1], 0, 0);
43 nn = nleft = n > sizeof(buf) ? sizeof(buf) : n;
46 sz = read(STDIN_FILENO, p, nleft);
50 fprintf(stderr, "%s: read error: %s", argv[0], strerror(errno));
53 fprintf(stderr, "%s: unexpected eof", argv[0]);
62 sz = write(STDOUT_FILENO, p, nleft);
66 fprintf(stderr, "%s: write error: %s", argv[0], strerror(errno));
69 fprintf(stderr, "%s: empty write", argv[0]);