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

74 lines
1.4 KiB
C
Raw Normal View History

/*
* simple malloc wrapper for sbrk
*
* Needed on platforms without malloc in libc, e.g. msb430
*
* Copyright (C) 2013 Freie Universität Berlin
*
2013-11-22 20:47:05 +01:00
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
2013-11-28 13:25:33 +01:00
*/
/**
* @ingroup core_util
* @{
*
* @file oneway_malloc.c
* @brief Simple malloc wrapper for SBRK
*
* Simple malloc implementation for plattforms without malloc in libc.
*
* @author Kaspar Schleiser <kaspar.schleiser@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ENABLE_DEBUG (0)
2013-12-16 17:54:58 +01:00
#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", (unsigned int) size, (unsigned int)ptr);
if (ptr != (void*) - 1) {
return ptr;
}
else {
return NULL;
}
}
void *_realloc(void *ptr, size_t size)
{
void *newptr = _malloc(size);
2010-09-30 16:07:00 +02:00
memcpy(newptr, ptr, size);
free(ptr);
return newptr;
}
2013-08-06 19:25:39 +02:00
void *_calloc(int size, size_t cnt)
{
void *mem = _malloc(size * cnt);
if (mem) {
memset(mem, 0, size * cnt);
}
return mem;
}
void _free(void *ptr)
{
2013-08-08 18:34:51 +02:00
/* who cares about pointers? */
(void) ptr;
DEBUG("_free(): block at 0x%X lost.\n", (unsigned int)ptr);
}