Brad Bishop | a669a50 | 2021-08-03 16:01:43 -0400 | [diff] [blame] | 1 | #include "utils.h" |
2 | |||||
3 | #include <stdlib.h> | ||||
4 | #include <string.h> | ||||
5 | |||||
6 | char** generate_test_sarray(size_t len) | ||||
7 | { | ||||
8 | static const char testString[] = "test"; | ||||
9 | size_t i; | ||||
10 | char** ret = calloc(len + 1, sizeof(*ret)); | ||||
11 | if (!ret) | ||||
George Liu | cf72403 | 2024-10-29 14:31:51 +0800 | [diff] [blame^] | 12 | { |
Brad Bishop | a669a50 | 2021-08-03 16:01:43 -0400 | [diff] [blame] | 13 | return NULL; |
George Liu | cf72403 | 2024-10-29 14:31:51 +0800 | [diff] [blame^] | 14 | } |
Brad Bishop | a669a50 | 2021-08-03 16:01:43 -0400 | [diff] [blame] | 15 | |
16 | for (i = 0; i < len; ++i) | ||||
17 | { | ||||
18 | ret[i] = strdup(testString); | ||||
19 | if (!ret[i]) | ||||
George Liu | cf72403 | 2024-10-29 14:31:51 +0800 | [diff] [blame^] | 20 | { |
Brad Bishop | a669a50 | 2021-08-03 16:01:43 -0400 | [diff] [blame] | 21 | goto error; |
George Liu | cf72403 | 2024-10-29 14:31:51 +0800 | [diff] [blame^] | 22 | } |
Brad Bishop | a669a50 | 2021-08-03 16:01:43 -0400 | [diff] [blame] | 23 | } |
24 | |||||
25 | return ret; | ||||
26 | |||||
27 | error: | ||||
28 | for (i = 0; i < len; ++i) | ||||
29 | { | ||||
30 | free(ret[i]); | ||||
31 | } | ||||
32 | free(ret); | ||||
33 | |||||
34 | return NULL; | ||||
35 | } |