This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
6377f630f6f21ed1585e32e4cc5afdc75c0bf127
[metaconfig.git] / U / compline / d_NOFILE.U
1 ?RCS: $Id: d_NOFILE.U,v 3.0.1.1 1994/10/29 16:08:38 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_NOFILE.U,v $
12 ?RCS: Revision 3.0.1.1  1994/10/29  16:08:38  ram
13 ?RCS: patch36: added ?F: line for metalint file checking
14 ?RCS:
15 ?RCS: Revision 3.0  1993/08/18  12:05:39  ram
16 ?RCS: Baseline for dist 3.0 netwide release.
17 ?RCS:
18 ?MAKE:nofile d_gettblsz tablesize: Compile Myread Guess cat \
19         test rm Csym +cc +ccflags +optimize +ldflags +libs
20 ?MAKE:  -pick add $@ %<
21 ?S:nofile:
22 ?S:     This variable contains the number of file descriptors available to the
23 ?S:     process.
24 ?S:.
25 ?S:d_gettblsz:
26 ?S:     This variable conditionally handles remapping of the getdtablesize()
27 ?S:     subroutine to ulimit(4,0), or the NOFILE manifest constant.
28 ?S:.
29 ?S:tablesize:
30 ?S:     This variable contains either the 'NOFILE' constant or 'ulimit(4, 0L)'
31 ?S:     and is used as the remapped value for the getdtablesize() macro.
32 ?S:.
33 ?C:getdtablesize:
34 ?C:     This catches use of the getdtablesize() subroutine, and remaps it
35 ?C:     to either ulimit(4,0) or NOFILE, if getdtablesize() isn't available.
36 ?C:.
37 ?C:VAL_NOFILE:
38 ?C:     This symbol contains the number of file descriptors available to the
39 ?C:     process, as determined at configuration time. Unless a static constant
40 ?C:     is needed, you should rely on getdtablesize() to obtain that number.
41 ?C:.
42 ?H:#$d_gettblsz getdtablesize() $tablesize      /**/
43 ?H:#define VAL_NOFILE $nofile   /* Number of file descriptors */
44 ?H:.
45 ?F:!nofile
46 ?T:d_ulimit4 val
47 : see if getdtablesize exists
48 echo " "
49 ?X: Revert logical value (d_gettblsz is undef iff getdtablesize is present)
50 case "$d_gettblsz" in
51 $define) d_gettblsz="$undef";;
52 $undef) d_gettblsz="$define";;
53 esac
54 if set getdtablesize val -f d_gettblsz; eval $csym; $val; then
55         echo 'getdtablesize() found.' >&4
56         d_gettblsz="$undef"
57         tablesize=''
58 @if VAL_NOFILE || nofile
59         $cat >nofile.c <<'EOCP'
60 #include <stdio.h>
61 int main()
62 {
63         printf("%d\n", getdtablesize());
64 }
65 EOCP
66         nofile=''
67         set nofile
68         if eval $compile_ok; then
69                 nofile=`./nofile 2>/dev/null`
70         fi
71         if $test "$nofile"; then
72                 echo "(You have $nofile file descriptors available per process.)"
73         else
74                 nofile='20'
75                 if ./bsd; then
76                         nofile='64'
77                 fi
78         echo "(Hmm... Let's say you have $nofile file descriptors available.)"
79         fi
80 @end
81 else
82         echo 'getdtablesize() NOT found...' >&4
83         if set ulimit val -f; eval $csym; $val; then
84                 echo 'Maybe ulimit(4,0) will work...'
85                 $cat >nofile.c <<'EOCP'
86 #include <stdio.h>
87 #ifdef GETPARAM_H
88 #include <sys/param.h>
89 #endif
90 int main()
91 {
92         printf("%d %d\n",
93 #ifdef NOFILE
94                 NOFILE,
95 #else
96                 0,
97 #endif
98                 ulimit(4,0));
99                 exit(0);
100 }
101 EOCP
102                 if $cc $optimize $ccflags -DGETPARAM_H $ldflags -o nofile nofile.c $libs >/dev/null 2>&1 \
103                         || $cc $optimize $ccflags $ldflags -o nofile nofile.c $libs >/dev/null 2>&1 ; then
104                         set `./nofile`
105                         d_gettblsz=$1
106                         d_ulimit4=$2
107                         if $test "$d_ulimit4" -lt 0; then
108                                 echo "Your ulimit() call doesn't tell me what I want to know."
109                                 echo "We'll just use NOFILE in this case."
110                                 nofile=$d_gettblsz
111                                 d_gettblsz="$define"
112                                 tablesize='NOFILE'
113                         else
114                                 if $test "$d_gettblsz" -gt 0; then
115                                 echo "Your system defines NOFILE to be $d_gettblsz, and" >&4
116                                 else
117                                 echo "I had trouble getting NOFILE from your system, but" >&4
118                                 fi
119 echo "ulimit returns $d_ulimit4 as the number of available file descriptors." >&4
120                                 dflt='y';
121                                 echo " "
122         rp='Should I use ulimit to get the number of available file descriptors?'
123                                 . ./myread
124                                 case "$ans" in
125                                 y*)
126                                         nofile=$d_ulimit4
127                                         d_gettblsz="$define"
128                                         tablesize='ulimit(4, 0L)'
129                                         echo "Using ulimit(4,0)."
130                                         ;;
131                                 *)
132                                         nofile=$d_gettblsz
133                                         d_gettblsz="$define"
134                                         tablesize='NOFILE'
135                                         echo "Using NOFILE."
136                                         ;;
137                                 esac
138                         fi
139                 else
140                         echo "Strange, I couldn't get my test program to compile."
141                         echo "We'll just use NOFILE in this case."
142                         d_gettblsz="$define"
143                         tablesize='NOFILE'
144                         nofile=''
145                 fi
146         else
147                 echo 'Using NOFILE instead.'
148                 d_gettblsz="$define"
149                 tablesize='NOFILE'
150                 nofile=''
151         fi
152 fi
153 @if VAL_NOFILE || nofile
154 case "$nofile" in
155 '')
156         $cat >nofile.c <<'EOCP'
157 #include <stdio.h>
158 #ifdef GETPARAM_H
159 #include <sys/param.h>
160 #endif
161 int main()
162 {
163         printf("%d\n",
164 #ifdef NOFILE
165                 NOFILE,
166 #else
167                 0,
168 #endif
169                 );
170                 exit(0);
171 }
172 EOCP
173         if $cc $ccflags -DGETPARAM_H nofile.c -o nofile $libs >/dev/null 2>&1 \
174                 || $cc $ccflags nofile.c -o nofile $libs >/dev/null 2>&1 ; then
175                 nofile=`./nofile 2>/dev/null`
176         fi
177         if $test "$nofile"; then
178                 echo "(You have $nofile file descriptors available per process.)"
179         else
180                 nofile='20'
181                 if ./bsd; then
182                         nofile='64'
183                 fi
184         echo "(Hmm... Let's say you have $nofile file descriptors available.)"
185         fi
186         ;;
187 esac
188 @end
189 $rm -f nofile*
190