Update.
[platform/upstream/glibc.git] / posix / bug-regex24.c
1 #include <regex.h>
2 #include <stdio.h>
3
4 #define str "civic"
5
6 #define N 10
7 static const char *expected[N] =
8   {
9     str, "c", "i", "", "", "", "", "", "", ""
10   };
11
12 static int
13 do_test (void)
14 {
15   regex_t rbuf;
16   static const char pat[] = "\
17 ^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$";
18
19   int err = regcomp (&rbuf, pat, REG_EXTENDED);
20   if (err != 0)
21     {
22       char errstr[300];
23       regerror (err, &rbuf, errstr, sizeof (errstr));
24       puts (errstr);
25       return err;
26     }
27
28   regmatch_t m[N];
29   err = regexec (&rbuf, str, N, m, 0);
30   if (err != 0)
31     {
32       puts ("regexec failed");
33       return 1;
34     }
35
36   int result = 0;
37   for (int i = 0; i < N; ++i)
38     if (m[i].rm_so == -1)
39       {
40         printf ("m[%d] unused\n", i);
41         result = 1;
42       }
43     else
44       {
45         int len = m[i].rm_eo - m[i].rm_so;
46
47         printf ("m[%d] = \"%.*s\"\n", i, len, str + m[i].rm_so);
48
49         if (strlen (expected[i]) != len
50             || memcmp (expected[i], str + m[i].rm_so, len) != 0)
51           result = 1;
52       }
53
54   return result;
55 }
56
57 #define TIMEOUT 30
58 #define TEST_FUNCTION do_test ()
59 #include "../test-skeleton.c"