blob: 67f3eab5057bfdd97c273f5fc6d26d5b231f639b [file] [log] [blame]
Brad Bishopa669a502021-08-03 16:01:43 -04001#include "utils.h"
2
3#include <stdlib.h>
4#include <string.h>
5
6char** 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 Liucf724032024-10-29 14:31:51 +080012 {
Brad Bishopa669a502021-08-03 16:01:43 -040013 return NULL;
George Liucf724032024-10-29 14:31:51 +080014 }
Brad Bishopa669a502021-08-03 16:01:43 -040015
16 for (i = 0; i < len; ++i)
17 {
18 ret[i] = strdup(testString);
19 if (!ret[i])
George Liucf724032024-10-29 14:31:51 +080020 {
Brad Bishopa669a502021-08-03 16:01:43 -040021 goto error;
George Liucf724032024-10-29 14:31:51 +080022 }
Brad Bishopa669a502021-08-03 16:01:43 -040023 }
24
25 return ret;
26
27error:
28 for (i = 0; i < len; ++i)
29 {
30 free(ret[i]);
31 }
32 free(ret);
33
34 return NULL;
35}