Back to index

glibc  2.9
bug-regex27.c
Go to the documentation of this file.
00001 /* Test REG_NEWLINE.
00002    Copyright (C) 2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <regex.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 
00025 struct tests
00026 {
00027   const char *regex;
00028   const char *string;
00029   int cflags;
00030   int retval;
00031 } tests[] = {
00032   { "a.b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH },
00033   { "a.b", "a\nb", REG_EXTENDED, 0 },
00034   { "a[^x]b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH },
00035   { "a[^x]b", "a\nb", REG_EXTENDED, 0 }
00036 };
00037 
00038 int
00039 main (void)
00040 {
00041   regex_t r;
00042   size_t i;
00043   int ret = 0;
00044 
00045   for (i = 0; i < sizeof (tests) / sizeof (tests[i]); ++i)
00046     {
00047       memset (&r, 0, sizeof (r));
00048       if (regcomp (&r, tests[i].regex, tests[i].cflags))
00049        {
00050          printf ("regcomp %zd failed\n", i);
00051          ret = 1;
00052          continue;
00053        }
00054       int rv = regexec (&r, tests[i].string, 0, NULL, 0);
00055       if (rv != tests[i].retval)
00056        {
00057          printf ("regexec %zd unexpected value %d != %d\n",
00058                 i, rv, tests[i].retval);
00059          ret = 1;
00060        }
00061       regfree (&r);
00062     }
00063   return ret;
00064 }