This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ad1b161a2f27a2533c7840ec7ea72114e03ee14c
[metaconfig.git] / U / compline / d_eofpipe.U
1 ?RCS: $Id: d_eofpipe.U,v 3.0.1.1 1994/10/29 16:12:40 ram Exp $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4 ?RCS:
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
10 ?RCS:
11 ?RCS: $Log: d_eofpipe.U,v $
12 ?RCS: Revision 3.0.1.1  1994/10/29  16:12:40  ram
13 ?RCS: patch36: call ./bsd explicitly instead of relying on PATH
14 ?RCS:
15 ?RCS: Revision 3.0  1993/08/18  12:05:57  ram
16 ?RCS: Baseline for dist 3.0 netwide release.
17 ?RCS:
18 ?MAKE:d_eofpipe: Compile cat rm Oldconfig Guess echo n c
19 ?MAKE:  -pick add $@ %<
20 ?S:d_eofpipe:
21 ?S:     This variable conditionally defines the EOFPIPE symbol, which
22 ?S:     indicates to the C program that select will correctly detect the EOF
23 ?S:     condition when pipe is closed from the other end.
24 ?S:.
25 ?C:EOFPIPE:
26 ?C:     This symbol, if defined, indicates that EOF condition will be detected
27 ?C:     by the reader of the pipe when it is closed by the writing process.
28 ?C:     That is, a select() call on that file descriptor will not block when
29 ?C:     only an EOF remains (typical behaviour for BSD systems).
30 ?C:.
31 ?H:#$d_eofpipe EOFPIPE          /**/
32 ?H:.
33 ?F:!mpipe
34 : see if pipe correctly gives the EOF condition
35 echo " "
36 case "$d_eofpipe" in
37 '')
38         echo "Let's see if your pipes return EOF to select() upon closing..." >&4
39         $cat >pipe.c <<'EOP'
40 int main()
41 {
42         int pd[2];
43         int mask;
44
45         pipe(pd);
46         if (0 == fork()) {
47                 close(pd[0]);
48                 close(pd[1]);
49                 exit(0);
50         }
51
52         close(pd[1]);
53         mask = 1 << pd[0];
54         alarm(2);
55         select(32, &mask, (int *) 0, (int *) 0, (char *) 0);
56         if (0 == read(pd[0], &mask, 1))
57                 exit(0);
58
59         exit(1);
60 }
61 EOP
62         set pipe
63         if eval $compile_ok; then
64 ?X: Use a script to avoid the possible 'alarm call' message
65                 echo "./pipe || exit 1" > mpipe
66                 chmod +x mpipe
67                 ./mpipe >/dev/null 2>&1
68                 case $? in
69                 0) d_eofpipe="$define";;
70                 *) d_eofpipe="$undef";;
71                 esac
72         else
73                 echo "(The test program did not compile correctly -- Guessing.)"
74                 if ./bsd; then
75                         d_eofpipe="$define"
76                 else
77                         d_eofpipe="$undef"
78                 fi
79         fi
80         case "$d_eofpipe" in
81         "$define") echo "Yes, they do.";;
82         *) echo "No, they don't! (sigh)";;
83         esac
84         ;;
85 *)
86         $echo $n "Your pipes $c"
87         case "$d_eofpipe" in
88         "$define") echo "allow select() to see EOF upon closing.";;
89         *) echo "won't let select() see EOF on closing.";;
90         esac
91         ;;
92 esac
93 $rm -f *pipe* core
94