Guest User

zcyes.c

a guest
Jun 13th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #define _GNU_SOURCE         /* See feature_test_macros(7) */
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <assert.h>
  6.  
  7. int main(int argc, char ** argv) {
  8.    const int bs = 4096;
  9.    unsigned char buf[bs];
  10.    for (int i = 0; i < bs; i+=2) {
  11.        buf[i] = 'y';
  12.        buf[i+1] = '\n';
  13.    }
  14.  
  15.    int p[2];
  16.    assert(pipe(p) == 0);
  17.    int r = fcntl(p[1], F_SETPIPE_SZ, bs);
  18.    fprintf(stderr, "bs %d r %d\n", bs, r);
  19.    assert(r >= bs);
  20.  
  21.    assert(write(p[1], buf, bs) == bs);
  22.  
  23.    while (1) {
  24.        int z = tee(p[0], STDOUT_FILENO, bs, 0);
  25.        if (z != bs) {
  26.            fprintf(stderr, "z %d bs %d\n", z, bs);
  27.        }
  28.        assert(z == bs);
  29.    }
  30.  
  31.    return 0;
  32. }
Add Comment
Please, Sign In to add comment