- processing of function parameter added (first tests successful)

- next stage -> constructing stub files (.c and .h)
This commit is contained in:
2017-03-03 14:07:38 +00:00
parent 444b9fb078
commit 9557e97bab
8 changed files with 167 additions and 37 deletions

View File

@@ -25,3 +25,49 @@ void* xmalloc(size_t size)
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;
}

View File

@@ -17,5 +17,7 @@
#include <malloc.h>
void *xmalloc(size_t size);
char* xmallocStrlcpy(char **aDest, char *aSource, size_t aSize);
char* xmallocStrlcat(char **aDest, char *aSource, size_t aSize);
#endif /* EXT_XMALLOC_H_ */

View File

@@ -1,13 +1,13 @@
/*!
* @file xstring.c
* @brief
* @brief
* @details
* Project: \n
* Subsystem: \n
* Module: \n
* Code: GNU-C\n
*
* @date 27.02.2017
*
* @date 27.02.2017
* @author SESA354004
*/
#include "xstring.h"
@@ -60,7 +60,7 @@ char* strntrimStatic(char *aStr, size_t aMaxLength)
end = aStr + strlen(aStr) - 1;
}
while (end > aStr && isspace((unsigned char)*end))
while (end > aStr && isspace((unsigned char )*end))
{
end--;
}
@@ -73,3 +73,53 @@ char* strntrimStatic(char *aStr, size_t aMaxLength)
return aStr;
}
void xStringTrim(char *aStr, size_t aMaxLength)
{
char *start;
char *end;
if (NULL == aStr)
{
return;
}
start = aStr;
// Trim leading space
while (isspace((unsigned char)*aStr) && 0 < aMaxLength)
{
if (--aMaxLength > 0)
{
++aStr;
}
}
// All spaces at termination or end of max length
if (*aStr == '\0' || 0 == aMaxLength)
{
start = '\0';
return;
}
(void) strlcpy(start, aStr, strlen(aStr) + 1);
// Trim trailing space
if (strlen(start) >= aMaxLength)
{
end = start + aMaxLength - 1;
}
else
{
end = start + strlen(start) - 1;
}
while (end > start && isspace((unsigned char )*end))
{
end--;
}
// Write new null terminator (if length is enough)
if (end < (start + aMaxLength - 1))
{
*(end + 1) = '\0';
}
}

View File

@@ -1,13 +1,13 @@
/*!
* @file xstring.h
* @brief
* @brief
* @details
* Project: \n
* Subsystem: \n
* Module: \n
* Code: GNU-C\n
*
* @date 27.02.2017
*
* @date 27.02.2017
* @author SESA354004
*/
#ifndef XSTRING_H_
@@ -17,5 +17,6 @@
char* gnu_basename(char *path);
char* strntrimStatic(char *aStr, size_t aMaxLength);
void xStringTrim(char *aStr, size_t aMaxLength);
#endif /* XSTRING_H_ */