GUI-FreeRDP/concat.c

38 lines
592 B
C
Raw Normal View History

/*
* concat.c
*
* Created on: 6 июл. 2022 г.
* Author: alexander
*/
#include "concat.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char* concat(char *s1, char *s2)
{
size_t len1 = s1 ? strlen(s1) : 0;
size_t len2 = s2 ? strlen(s2) : 0;
char *result = malloc(len1 + len2 + 1);
if (!result)
{
fprintf(stderr, "malloc() failed: insufficient memory!\n");
return NULL;
}
if (s1)
{
memcpy(result, s1, len1);
}
if (s2)
{
memcpy(result + len1, s2, len2 + 1);
}
return result;
}