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