This source file includes following definitions.
- handler
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <signal.h>
20
21
22 int s = SIGPIPE;
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28
29 #include "macros.h"
30
31 static void
32 handler (int sig)
33 {
34 exit (0);
35 }
36
37 int
38 main (int argc, char **argv)
39 {
40 char mode = argv[1][0];
41
42 switch (mode)
43 {
44 case 'A': signal (SIGPIPE, SIG_DFL); break;
45 case 'B': signal (SIGPIPE, SIG_IGN); break;
46 case 'C': signal (SIGPIPE, handler); break;
47 }
48
49
50
51 for (;;)
52 {
53 char c[2] = { 'y', '\n' };
54 int ret = write (1, c, sizeof (c));
55 if (ret <= 0)
56 {
57 switch (mode)
58 {
59 case 'B':
60 if (ret < 0 && errno == EPIPE)
61 exit (0);
62 FALLTHROUGH;
63 case 'A':
64 case 'C':
65 fprintf (stderr, "write() returned %d with error %d.\n", ret, errno);
66 exit (1);
67 }
68 }
69 }
70 }