Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Test for bug BZ #2703. */
2#include <stdio.h>
3#include <envz.h>
4#include <stdlib.h>
5#include <string.h>
6
7static const struct
8{
9 const char *s;
10 int in_result;
11} strs[] =
12{
13 { "a=1", 1 },
14 { "b=2", 1 },
15 { "(*)", 0 },
16 { "(*)", 0 },
17 { "e=5", 1 },
18 { "f=", 1 },
19 { "(*)", 0 },
20 { "h=8", 1 },
21 { "i=9", 1 },
22 { "j", 0 }
23};
24
25#define nstrs (sizeof (strs) / sizeof (strs[0]))
26
27
28int
29do_test (void)
30{
31
32 size_t size = 0;
33 char *str = malloc (100);
34 if (str == NULL)
35 {
36 puts ("out of memory");
37 return 1;
38 }
39
40 char **argz = &str;
41
42 for (int i = 0; i < nstrs; ++i)
43 argz_add_sep (argz, &size, strs[i].s, '\0');
44
45 printf ("calling envz_strip with size=%zu\n", size);
46 envz_strip (argz, &size);
47
48 int result = 0;
49 printf ("new size=%zu\n", size);
50 for (int i = 0; i < nstrs; ++i)
51 if (strs[i].in_result)
52 {
53 char name[2];
54 name[0] = strs[i].s[0];
55 name[1] = '\0';
56
57 char *e = envz_entry (*argz, size, name);
58 if (e == NULL)
59 {
60 printf ("entry '%s' not found\n", name);
61 result = 1;
62 }
63 else if (strcmp (e, strs[i].s) != 0)
64 {
65 printf ("entry '%s' does not match: is '%s', expected '%s'\n",
66 name, e, strs[i].s);
67 result = 1;
68 }
69 }
70
71 free (*argz);
72 return result;
73}
74
75#include <support/test-driver.c>
76

Warning: That file was not part of the compilation database. It may have many parsing errors.