Update.
[glibc.git] / sysdeps / generic / sbrk.c
blob4df883b59e58116defb0469ec058904096a9dafa
1 /* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <unistd.h>
20 #include <errno.h>
22 /* Defined in brk.c. */
23 extern void *__curbrk;
24 extern int __brk (void *addr);
26 extern int __libc_multiple_libcs; /* Defined in init-first.c. */
28 /* Extend the process's data space by INCREMENT.
29 If INCREMENT is negative, shrink data space by - INCREMENT.
30 Return start of new space allocated, or -1 for errors. */
31 void *
32 __sbrk (ptrdiff_t increment)
34 void *oldbrk;
36 /* If this is not part of the dynamic library or the library is used
37 via dynamic loading in a statically linked program update
38 __curbrk from the kernel's brk value. That way two separate
39 instances of __brk and __sbrk can share the heap, returning
40 interleaved pieces of it. */
41 if (__curbrk == NULL || __libc_multiple_libcs)
42 if (__brk (0) < 0) /* Initialize the break. */
43 return (void *) -1;
45 if (increment == 0)
46 return __curbrk;
48 oldbrk = __curbrk;
49 if (__brk (oldbrk + increment) < 0)
50 return (void *) -1;
52 return oldbrk;
55 weak_alias (__sbrk, sbrk)