This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Plan 9: No Configure.
[metaconfig.git] / U / compline / sbrksmart.U
1 ?RCS: $Id: sbrksmart.U,v 3.0.1.2 1995/01/11 15:35:41 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: 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 explicitely 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 Compile 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 : see if sbrk can release core to the kernel
35 echo " "
36 case "$d_sbrk" in
37 "$define")
38         echo "Let's see if your sbrk() is smart enough to release core..." >&4
39         $cat > sbrk.c <<'EOC'
40 #define INC 256         /* Small enough to be less than a page size */
41
42 int main()
43 {
44         char *obrk = (char *) sbrk(0);
45         char *nbrk;
46
47         nbrk = (char *) sbrk(INC);
48         if (nbrk == (char *) -1)
49                 exit(1);        /* Not enough memory */
50         if (nbrk != obrk)
51                 exit(2);        /* Unreliable sbrk() */
52         nbrk = (char *) sbrk(-INC);
53         if (nbrk == (char *) -1)
54                 exit(3);        /* May have understood negative arg as huge positive */
55         if (obrk != (char *) sbrk(0))
56                 exit(4);        /* Not smart, definitely */
57
58         exit(0);                /* Ok */
59 }
60 EOC
61         sbrksmart="$undef"
62         dumb='-- assuming dumb sbrk().'
63         set sbrk
64         if eval $compile_ok; 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         ;;
83 esac
84 $rm -f sbrk sbrk.* core
85