blob: 02b33f1c6363b3ec64ba9c814a8485f27258e71a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include "strings.h"
#include <stdlib.h>
int strprefix(const char* prefix, const char* str) {
return strncmp(prefix, str, strlen(prefix)) == 0;
}
int streq(const char* a, const char* b) {
return strncmp(a, b, strlen(a)) == 0;
}
char* concat_array(const char** array, size_t size, size_t *output_size) {
if (array == NULL || size == 0) return NULL;
size_t total_size = 0;
for (size_t i = 0; i < size; i++)
total_size += strlen(array[i]);
if (total_size == 0) return NULL;
char* result = malloc(total_size + 1);
size_t current_index = 0;
for (size_t i = 0; i < size; i++) {
size_t curr_len = strlen(array[i]);
strncpy(result + current_index, array[i], curr_len);
current_index += curr_len;
}
if (output_size != NULL) *output_size = total_size;
return result;
}
|