]> git.ozlabs.org Git - ccan/blob - ccan/tal/str/test/run-strndup.c
tal/str: always create strings which have tal_count() == strlen() + 1.
[ccan] / ccan / tal / str / test / run-strndup.c
1 #include <ccan/tal/str/str.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <ccan/tal/str/str.c>
5 #include <ccan/tap/tap.h>
6 #include "helper.h"
7
8 int main(void)
9 {
10         char *str, *copy;
11
12         plan_tests(2);
13         str = malloc(5);
14         memcpy(str, "hello", 5);
15         /* We should be fine to strndup src without nul terminator. */
16         copy = tal_strndup(NULL, str, 5);
17         ok1(!strcmp(copy, "hello"));
18         ok1(tal_count(copy) == strlen(copy) + 1);
19         tal_free(copy);
20         free(str);
21
22         return exit_status();
23 }