File: pipe5.c

package info (click to toggle)
gdb-doc 16.3-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid, trixie
  • size: 244,264 kB
  • sloc: ansic: 2,134,731; asm: 375,582; exp: 206,875; cpp: 73,639; makefile: 70,232; sh: 26,038; python: 13,697; yacc: 11,341; ada: 7,358; xml: 6,098; perl: 5,077; pascal: 3,389; tcl: 2,986; f90: 2,764; lisp: 1,984; cs: 879; lex: 738; sed: 228; awk: 181; objc: 137; fortran: 57
file content (59 lines) | stat: -rw-r--r-- 1,368 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Check that TRT happens for pipe corner cases (for our definition of TRT).
#progos: linux
#xerror:
#output: Terminating simulation due to writing pipe * from one single thread\n
#output: program stopped with signal 4 (*).\n
*/
#include <stddef.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>

void err (const char *s)
{
  perror (s);
  abort ();
}

int main (void)
{
  int pip[2];
  int pipemax;
  char *buf;

  if (pipe (pip) != 0)
    err ("pipe");

#ifdef PIPE_MAX
  pipemax = PIPE_MAX;
#else
  pipemax = fpathconf (pip[1], _PC_PIPE_BUF);
#endif

  if (pipemax <= 0)
    {
      fprintf (stderr, "Bad pipemax %d\n", pipemax);
      abort ();
    }

  /* Writing an inordinate amount to the pipe.  */
  buf = calloc (100 * pipemax, 1);
  if (buf == NULL)
    err ("calloc");

  /* The following doesn't trig on host; writing more than PIPE_MAX to a
     pipe with no reader makes the program hang.  Neither does it trig
     on target: we don't want to emulate the "hanging" (which would
     happen with *any* amount written to a pipe with no reader if we'd
     support it - but we don't).  Better to abort the simulation with a
     suitable message.  */
  if (write (pip[1], buf, 100 * pipemax) != -1
      || errno != EFBIG)
    err ("write mucho");

  printf ("pass\n");
  exit (0);
}