Back to index

glibc  2.9
bug-envz1.c
Go to the documentation of this file.
00001 /* Test for bug BZ #2703.  */
00002 #include <stdio.h>
00003 #include <envz.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 
00007 static const struct
00008 {
00009   const char *s;
00010   int in_result;
00011 } strs[] =
00012 {
00013   { "a=1", 1 },
00014   { "b=2", 1 },
00015   { "(*)", 0 },
00016   { "(*)", 0 },
00017   { "e=5", 1 },
00018   { "f=", 1 },
00019   { "(*)", 0 },
00020   { "h=8", 1 },
00021   { "i=9", 1 },
00022   { "j", 0 }
00023 };
00024 
00025 #define nstrs (sizeof (strs) / sizeof (strs[0]))
00026 
00027 
00028 static int
00029 do_test (void)
00030 {
00031 
00032   size_t size = 0;
00033   char *str = malloc (100);
00034   if (str == NULL)
00035     {
00036       puts ("out of memory");
00037       return 1;
00038     }
00039 
00040   char **argz = &str;
00041 
00042   for (int i = 0; i < nstrs; ++i)
00043     argz_add_sep (argz, &size, strs[i].s, '\0');
00044 
00045   printf ("calling envz_strip with size=%zu\n", size);
00046   envz_strip (argz, &size);
00047 
00048   int result = 0;
00049   printf ("new size=%zu\n", size);
00050   for (int i = 0; i < nstrs; ++i)
00051     if (strs[i].in_result)
00052       {
00053         char name[2];
00054         name[0] = strs[i].s[0];
00055         name[1] = '\0';
00056 
00057         char *e = envz_entry (*argz, size, name);
00058         if (e == NULL)
00059           {
00060             printf ("entry '%s' not found\n", name);
00061             result = 1;
00062           }
00063         else if (strcmp (e, strs[i].s) != 0)
00064           {
00065             printf ("entry '%s' does not match: is '%s', expected '%s'\n",
00066                     name, e, strs[i].s);
00067             result = 1;
00068           }
00069       }
00070 
00071   free (*argz);
00072   return result;
00073 }
00074 
00075 #define TEST_FUNCTION do_test ()
00076 #include "../test-skeleton.c"