aboutsummaryrefslogtreecommitdiff
path: root/string/bug-envz1.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
commit0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch)
tree2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /string/bug-envz1.c
parent7d58530341304d403a6626d7f7a1913165fe2f32 (diff)
downloadglibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.bz2
2.5-18.1
Diffstat (limited to 'string/bug-envz1.c')
-rw-r--r--string/bug-envz1.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/string/bug-envz1.c b/string/bug-envz1.c
new file mode 100644
index 0000000..e8a6097
--- /dev/null
+++ b/string/bug-envz1.c
@@ -0,0 +1,76 @@
+/* Test for bug BZ #2703. */
+#include <stdio.h>
+#include <envz.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const struct
+{
+ const char *s;
+ int in_result;
+} strs[] =
+{
+ { "a=1", 1 },
+ { "b=2", 1 },
+ { "(*)", 0 },
+ { "(*)", 0 },
+ { "e=5", 1 },
+ { "f=", 1 },
+ { "(*)", 0 },
+ { "h=8", 1 },
+ { "i=9", 1 },
+ { "j", 0 }
+};
+
+#define nstrs (sizeof (strs) / sizeof (strs[0]))
+
+
+static int
+do_test (void)
+{
+
+ size_t size = 0;
+ char *str = malloc (100);
+ if (str == NULL)
+ {
+ puts ("out of memory");
+ return 1;
+ }
+
+ char **argz = &str;
+
+ for (int i = 0; i < nstrs; ++i)
+ argz_add_sep (argz, &size, strs[i].s, '\0');
+
+ printf ("calling envz_strip with size=%zu\n", size);
+ envz_strip (argz, &size);
+
+ int result = 0;
+ printf ("new size=%zu\n", size);
+ for (int i = 0; i < nstrs; ++i)
+ if (strs[i].in_result)
+ {
+ char name[2];
+ name[0] = strs[i].s[0];
+ name[1] = '\0';
+
+ char *e = envz_entry (*argz, size, name);
+ if (e == NULL)
+ {
+ printf ("entry '%s' not found\n", name);
+ result = 1;
+ }
+ else if (strcmp (e, strs[i].s) != 0)
+ {
+ printf ("entry '%s' does not match: is '%s', expected '%s'\n",
+ name, e, strs[i].s);
+ result = 1;
+ }
+ }
+
+ free (*argz);
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"