This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the files from dist/meta to perl's repo
[metaconfig.git] / dist / U / d_NOFILE.U
CommitLineData
d8875586
MBT
1?RCS: $Id: d_NOFILE.U 1 2006-08-24 12:32:52Z rmanfredi $
2?RCS:
3?RCS: Copyright (c) 1991-1997, 2004-2006, 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 4.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: Myread Guess cat +cc +ccflags +libs \
19 test rm Csym
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
48echo " "
49?X: Revert logical value (d_gettblsz is undef iff getdtablesize is present)
50case "$d_gettblsz" in
51$define) d_gettblsz="$undef";;
52$undef) d_gettblsz="$define";;
53esac
54if 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>
61int main()
62{
63 printf("%d\n", getdtablesize());
64}
65EOCP
66 nofile=''
67 if $cc $ccflags -o nofile nofile.c $libs >/dev/null 2>&1; then
68 nofile=`./nofile 2>/dev/null`
69 fi
70 if $test "$nofile"; then
71 echo "(You have $nofile file descriptors available per process.)"
72 else
73 nofile='20'
74 if ./bsd; then
75 nofile='64'
76 fi
77 echo "(Hmm... Let's say you have $nofile file descriptors available.)"
78 fi
79@end
80else
81 echo 'getdtablesize() NOT found...' >&4
82 if set ulimit val -f; eval $csym; $val; then
83 echo 'Maybe ulimit(4,0) will work...'
84 $cat >nofile.c <<'EOCP'
85#include <stdio.h>
86#ifdef GETPARAM_H
87#include <sys/param.h>
88#endif
89int main()
90{
91 printf("%d %d\n",
92#ifdef NOFILE
93 NOFILE,
94#else
95 0,
96#endif
97 ulimit(4,0));
98 exit(0);
99}
100EOCP
101 if $cc $ccflags -DGETPARAM_H -o nofile nofile.c $libs >/dev/null 2>&1 \
102 || $cc $ccflags -o nofile nofile.c $libs >/dev/null 2>&1 ; then
103 set `./nofile`
104 d_gettblsz=$1
105 d_ulimit4=$2
106 if $test "$d_ulimit4" -lt 0; then
107 echo "Your ulimit() call doesn't tell me what I want to know."
108 echo "We'll just use NOFILE in this case."
109 nofile=$d_gettblsz
110 d_gettblsz="$define"
111 tablesize='NOFILE'
112 else
113 if $test "$d_gettblsz" -gt 0; then
114 echo "Your system defines NOFILE to be $d_gettblsz, and" >&4
115 else
116 echo "I had trouble getting NOFILE from your system, but" >&4
117 fi
118echo "ulimit returns $d_ulimit4 as the number of available file descriptors." >&4
119 dflt='y';
120 echo " "
121 rp='Should I use ulimit to get the number of available file descriptors?'
122 . ./myread
123 case "$ans" in
124 y*)
125 nofile=$d_ulimit4
126 d_gettblsz="$define"
127 tablesize='ulimit(4, 0L)'
128 echo "Using ulimit(4,0)."
129 ;;
130 *)
131 nofile=$d_gettblsz
132 d_gettblsz="$define"
133 tablesize='NOFILE'
134 echo "Using NOFILE."
135 ;;
136 esac
137 fi
138 else
139 echo "Strange, I couldn't get my test program to compile."
140 echo "We'll just use NOFILE in this case."
141 d_gettblsz="$define"
142 tablesize='NOFILE'
143 nofile=''
144 fi
145 else
146 echo 'Using NOFILE instead.'
147 d_gettblsz="$define"
148 tablesize='NOFILE'
149 nofile=''
150 fi
151fi
152@if VAL_NOFILE || nofile
153case "$nofile" in
154'')
155 $cat >nofile.c <<'EOCP'
156#include <stdio.h>
157#ifdef GETPARAM_H
158#include <sys/param.h>
159#endif
160int main()
161{
162 printf("%d\n",
163#ifdef NOFILE
164 NOFILE,
165#else
166 0,
167#endif
168 );
169 exit(0);
170}
171EOCP
172 if $cc $ccflags -DGETPARAM_H -o nofile nofile.c $libs >/dev/null 2>&1 \
173 || $cc $ccflags -o nofile nofile.c $libs >/dev/null 2>&1 ; then
174 nofile=`./nofile 2>/dev/null`
175 fi
176 if $test "$nofile"; then
177 echo "(You have $nofile file descriptors available per process.)"
178 else
179 nofile='20'
180 if ./bsd; then
181 nofile='64'
182 fi
183 echo "(Hmm... Let's say you have $nofile file descriptors available.)"
184 fi
185 ;;
186esac
187@end
188$rm -f nofile*
189