summaryrefslogtreecommitdiff
path: root/tests/libc/test_malloc.c
blob: aaff2da9f58ddeb9e723aeb062b2ec2d3fff75fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdlib.h"
#include "string.h"

#define HEAP_SIZE 128 * 1024

int main( void )
{
	memory_manager_t memory_manager;
	char buf[HEAP_SIZE];
	uint32_t heap_offset = (uint32_t)&buf;
	size_t heap_size = HEAP_SIZE;
	memory_manager_init( &memory_manager, heap_offset, heap_size );
	__stdlib_set_memory_manager( &memory_manager );
	
	char *s;
	char *s1 = "test_string";
	
	s = (char *)malloc( strlen( s1 ) + 1 );
	size_t n = strlcpy( s, s1, strlen( s1 ) + 1 );
	if( n != 11 ) exit( 1 );
	if( strcmp( s, s1 ) != 0 ) exit( 1 );
	
	exit( 0 );
}