21 lines
444 B
C
21 lines
444 B
C
#include "utils.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
char* alloc_cstring(const char* source)
|
|
{
|
|
char* destination = malloc(strlen(source) + 1);
|
|
strcpy(destination, source);
|
|
return destination;
|
|
}
|
|
|
|
AllocatedString alloc_string(const char* source, size_t length)
|
|
{
|
|
char* value = malloc(length + 1);
|
|
strncpy(value, source, length);
|
|
return (AllocatedString) {
|
|
.value = value,
|
|
.length = length,
|
|
};
|
|
}
|