1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/core/oneway_malloc.c
Oliver Hahm fb1cb91c75 [board/msp-430-common board/msba2 core/]
* introduced dummy function for msp-430 config-save
* moved sysconfig from board to core

[sys/transceiver cpu/]
* moved some buffer size defines to cpu dependent parts

* some cleanups
2010-12-03 18:42:03 +01:00

51 lines
1.0 KiB
C

/**
* simple malloc wrapper for sbrk
*
* Needed on platforms without malloc in libc, e.g. msb430
*
* Copyright (C) 2010 Freie Universität Berlin
*
* This file subject to the terms and conditions of the GNU General Public
* License. See the file LICENSE in the top level directory for more details.
*
* @ingroup kernel
* @{
* @file
* @author Kaspar Schleiser <kaspar.schleiser@fu-berlin.de>
* @}
*/
#include <stdio.h>
#include <sys/unistd.h>
#include <string.h>
#include <stdlib.h>
#define ENABLE_DEBUG
#include <debug.h>
extern void *sbrk(int incr);
void *_malloc(size_t size) {
void* ptr = sbrk(size);
DEBUG("_malloc(): allocating block of size %u at 0x%X.\n", size, (unsigned int)ptr);
if (ptr != (void*)-1) {
return ptr;
} else {
return NULL;
}
}
void *_realloc(void *ptr, size_t size) {
void* newptr = _malloc(size);
memcpy(newptr, ptr, size);
free(ptr);
return newptr;
}
void _free(void* ptr) {
DEBUG("_free(): block at 0x%X lost.\n", (unsigned int)ptr);
}