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 / sbrksmart.U
CommitLineData
d8875586
MBT
1?RCS: $Id: sbrksmart.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: sbrksmart.U,v $
12?RCS: Revision 3.0.1.2 1995/01/11 15:35:41 ram
13?RCS: patch45: now sets sbrksmart to undef explicitly when lacking sbrk()
14?RCS: patch45: forgot a cast when using return value from sbrk()
15?RCS:
16?RCS: Revision 3.0.1.1 1994/01/24 14:16:45 ram
17?RCS: patch16: created
18?RCS:
19?MAKE:sbrksmart: cat d_sbrk +cc +ccflags +libs rm
20?MAKE: -pick add $@ %<
21?S:sbrksmart:
22?S: This variable conditionally defines HAS_SMART_SBRK if the sbrk()
23?S: routine honors a negative argument to lower the break value.
24?S:.
25?C:HAS_SMART_SBRK:
26?C: This symbol is defined when the sbrk() system call may be used with
27?C: a negative argument to lower the break value, therefore releasing
28?C: core to the system. If not, you'd probably be better off using the
29?C: mmap() system call.
30?C:.
31?H:#$sbrksmart HAS_SMART_SBRK /**/
32?H:.
33?T:dumb
34?F:!sbrk
35: see whether sbrk can release core to the kernel
36echo " "
37case "$d_sbrk" in
38"$define")
39 echo "Let's see if your sbrk() is smart enough to release core..." >&4
40 $cat > sbrk.c <<'EOC'
41#define INC 256 /* Small enough to be less than a page size */
42
43int main()
44{
45 char *obrk = (char *) sbrk(0);
46 char *nbrk;
47
48 nbrk = (char *) sbrk(INC);
49 if (nbrk == (char *) -1)
50 exit(1); /* Not enough memory */
51 if (nbrk != obrk)
52 exit(2); /* Unreliable sbrk() */
53 nbrk = (char *) sbrk(-INC);
54 if (nbrk == (char *) -1)
55 exit(3); /* May have understood negative arg as huge positive */
56 if (obrk != (char *) sbrk(0))
57 exit(4); /* Not smart, definitely */
58
59 exit(0); /* Ok */
60}
61EOC
62 sbrksmart="$undef"
63 dumb='-- assuming dumb sbrk().'
64 if $cc $ccflags -o sbrk sbrk.c $libs >/dev/null 2>&1; then
65 ./sbrk >/dev/null 2>&1
66 case $? in
67 0) sbrksmart="$define"
68 echo "Yes, it can be used with negative values." ;;
69 1) echo "Sorry, not enough memory $dumb" ;;
70 2) echo "No it's not, and besides it seems to be buggy..." ;;
71 3) echo "No, it fails with negative values." ;;
72 4) echo "Nope, your sbrk() is too dumb." ;;
73 *) echo "Err... Unexpected result $dumb" ;;
74 esac
75 else
76 echo "(Could not compile test program $dumb)"
77 fi
78 ;;
79*)
80 echo "Since you don't have sbrk(), let's forget about the smart test!"
81 sbrksmart="$undef"
82 ;;
83esac
84$rm -f sbrk sbrk.* core
85