* io/bits/fcntl2.h (open, open64, openat, openat64): Add
[glibc/pb-stable.git] / string / bug-envz1.c
blobe8a60972b5f7af3ea5215c5f55d449da4a224c68
1 /* Test for bug BZ #2703. */
2 #include <stdio.h>
3 #include <envz.h>
4 #include <stdlib.h>
5 #include <string.h>
7 static const struct
9 const char *s;
10 int in_result;
11 } strs[] =
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 }
25 #define nstrs (sizeof (strs) / sizeof (strs[0]))
28 static int
29 do_test (void)
32 size_t size = 0;
33 char *str = malloc (100);
34 if (str == NULL)
36 puts ("out of memory");
37 return 1;
40 char **argz = &str;
42 for (int i = 0; i < nstrs; ++i)
43 argz_add_sep (argz, &size, strs[i].s, '\0');
45 printf ("calling envz_strip with size=%zu\n", size);
46 envz_strip (argz, &size);
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)
53 char name[2];
54 name[0] = strs[i].s[0];
55 name[1] = '\0';
57 char *e = envz_entry (*argz, size, name);
58 if (e == NULL)
60 printf ("entry '%s' not found\n", name);
61 result = 1;
63 else if (strcmp (e, strs[i].s) != 0)
65 printf ("entry '%s' does not match: is '%s', expected '%s'\n",
66 name, e, strs[i].s);
67 result = 1;
71 free (*argz);
72 return result;
75 #define TEST_FUNCTION do_test ()
76 #include "../test-skeleton.c"