libc/newlib/libc/sys/linux/brk.c
Jeff Johnston ad5527663e 2002-08-17 Jeff Johnston <jjohnstn@redhat.com>
*  Makefile.am: Move cmath stuff into libc/sys/linux.
        *  Makefile.in: Regenerated.
        *  configure.host: Default -DMB_CAPABLE for x86-linux.
        *  libc/include/reent.h: Define _sbrk to take signed int argument.
        *  libc/include/sys/unistd.h: Ditto for _sbrk_r and sbrk.
        *  libc/locale/locale.c[MB_CAPABLE]: Add LC_MESSAGES support and
        make locale name checking more efficient.  Also allow "C-ISO-8859-1"
        locale for LC_CTYPE and LC_MESSAGES.
        *  libc/reent/sbrkr.c: Change prototype to take ptrdiff_t.
        *  libc/sys/linux/brk.c: Change sbrk prototype.
        *  libc/sys/linux/include/time.h: Remove Cygwin stuff and
        include <sys/features.h>.
        (CLOCK_THREAD_CPUTIME): Renamed to CLOCK_THREAD_CPUTIME_ID.
        (CLOCK_PROCESS_CPUTIME): Renamed to CLOCK_PROCESS_CPUTIME_ID.
        *  libc/sys/linux/sys/cdefs.h: Replace with glibc sys/cdefs.h
        with a few local additions.
        *  libc/sys/linux/sys/features.h: New file.
        *  libc/sys/linux/sys/unistd.h: Change _sbrk_r and sbrk prototypes
        to take signed argument.
        *  libc/syscalls/syssbrk.c: Change sbrk, _sbrk_r, and _sbrk
        prototypes to take signed size argument.
2002-08-17 05:19:18 +00:00

42 lines
851 B
C

/* libc/sys/linux/brk.c - Change data segment size */
/* Written 2000 by Werner Almesberger */
#include <stddef.h> /* for NULL */
#include <sys/types.h>
#include <sys/unistd.h>
#include <machine/syscall.h>
static char *curr_brk = NULL;
#define __NR___brk __NR_brk /* Linux brk ain't no brk(2) */
static _syscall1(void *,__brk,void *,end_data_segment)
int brk(void *end_data_segment)
{
char *new_brk;
new_brk = __brk(end_data_segment);
if (new_brk != end_data_segment) return -1;
curr_brk = new_brk;
return 0;
}
void *sbrk(ptrdiff_t increment) /* SHOULD be ptrdiff_t */
{
char *old_brk,*new_brk;
if (!curr_brk) curr_brk = __brk(NULL);
new_brk = __brk(curr_brk+increment);
if (new_brk != curr_brk+increment) return (void *) -1;
old_brk = curr_brk;
curr_brk = new_brk;
return old_brk;
}