OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [brk.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* libc/sys/linux/brk.c - Change data segment size */
2
 
3
/* Written 2000 by Werner Almesberger */
4
 
5
 
6
#include <stddef.h> /* for NULL */
7
#include <sys/types.h>
8
#include <sys/unistd.h>
9
#include <machine/syscall.h>
10
 
11
 
12
static char *curr_brk = NULL;
13
 
14
 
15
#define __NR___brk __NR_brk /* Linux brk ain't no brk(2) */
16
 
17
static _syscall1(void *,__brk,void *,end_data_segment)
18
 
19
 
20
int brk(void *end_data_segment)
21
{
22
     char *new_brk;
23
 
24
     new_brk = __brk(end_data_segment);
25
     if (new_brk != end_data_segment) return -1;
26
     curr_brk = new_brk;
27
     return 0;
28
}
29
 
30
 
31
void *sbrk(ptrdiff_t increment) /* SHOULD be ptrdiff_t */
32
{
33
    char *old_brk,*new_brk;
34
 
35
    if (!curr_brk) curr_brk = __brk(NULL);
36
    new_brk = __brk(curr_brk+increment);
37
    if (new_brk != curr_brk+increment) return (void *) -1;
38
    old_brk = curr_brk;
39
    curr_brk = new_brk;
40
    return old_brk;
41
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.