source: trunk/libs/newlib/src/libgloss/moxie/sbrk.c @ 487

Last change on this file since 487 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.4 KB
RevLine 
[444]1/* sbrk.c -- allocate memory dynamically.
2 *
3 * Copyright (c) 2008 Anthony Green
4 *
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
13 * they apply.
14 */
15#include <errno.h>
16#include "glue.h"
17
18/* just in case, most boards have at least some memory */
19#ifndef RAMSIZE
20#  define RAMSIZE             (caddr_t)0x100000
21#endif
22
23char *__heap_ptr = (char *)&_end;
24
25/*
26 * sbrk -- changes heap size size. Get nbytes more
27 *         RAM. We just increment a pointer in what's
28 *         left of memory on the board.
29 */
30char *
31_sbrk (nbytes)
32     int nbytes;
33{
34  char *base;
35  char *sp;
36
37  base = __heap_ptr;
38  __heap_ptr += nbytes;
39
40  return base;
41/* FIXME: We really want to make sure we don't run out of RAM, but this
42 *       isn't very portable.
43 */
44#if 0
45  if ((RAMSIZE - heap_ptr - nbytes) >= 0) {
46    base = heap_ptr;
47    heap_ptr += nbytes;
48    return (base);
49  } else {
50    errno = ENOMEM;
51    return ((char *)-1);
52  }
53#endif
54}
Note: See TracBrowser for help on using the repository browser.