Files
stubser/src/ext/xmalloc.c
Martin Winkler 9557e97bab - processing of function parameter added (first tests successful)
- next stage -> constructing stub files (.c and .h)
2017-03-03 14:07:38 +00:00

74 lines
1.3 KiB
C

/*!
* @file xmalloc.c
* @brief
* @details
* Project: \n
* Subsystem: \n
* Module: \n
* Code: GNU-C\n
*
* @date 28.02.2017
* @author SESA354004
*/
#include <stdio.h>
#include <string.h>
#include "xmalloc.h"
#include "xtypes.h"
void* xmalloc(size_t size)
{
void *value = malloc(size);
if (value == 0)
perror("virtual memory exhausted");
else
memset(value, 0, size);
return value;
}
char* xmallocStrlcpy(char **aDest, char *aSource, size_t aSize)
{
if (NULL == aSource || 0 == aSize)
{
return NULL;
}
if (NULL != *aDest)
{
*aDest = (char*) realloc(*aDest, aSize + 1);
}
else
{
*aDest = (char*) xmalloc(aSize + 1);
}
if (NULL != *aDest)
{
(void) strlcpy(*aDest, aSource, aSize + 1);
}
return *aDest;
}
char* xmallocStrlcat(char **aDest, char *aSource, size_t aSize)
{
size_t newSize = 0;
if (NULL == aSource || 0 == aSize)
{
return NULL;
}
if (NULL != *aDest)
{
newSize = strlen(*aDest) + aSize + 1;
*aDest = (char*) realloc(*aDest, newSize);
}
else
{
newSize = aSize + 1;
*aDest = (char*) xmalloc(newSize);
}
if (NULL != *aDest)
{
(void) strlcat(*aDest, aSource, newSize);
}
return *aDest;
}