GUI-FreeRDP/concat.c

38 lines
601 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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 = (char *)malloc(sizeof(char) * (len1 + len2 + 1));
if (!result)
{
fprintf(stderr, "malloc() failed: insufficient memory!\n");
return NULL;
}
if (s1)
{
strcpy(result, s1);
}
if (s2)
{
strcpy(result + len1, s2);
}
return result;
}