tst-regexloc.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (C) 2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sys/types.h>
  15. #include <regex.h>
  16. #include <locale.h>
  17. #include <stdio.h>
  18. int
  19. main (int argc, char *argv[])
  20. {
  21. /* If uclibc has extended locale, or if it's a host build
  22. * (assuming host libc always has locale): */
  23. #if defined __UCLIBC_HAS_XLOCALE__ || (defined(__GLIBC__) && !defined __UCLIBC__)
  24. regex_t re;
  25. regmatch_t mat[1];
  26. int exitcode = 1;
  27. if (setlocale (LC_ALL, "de_DE.ISO-8859-1") == NULL)
  28. puts ("cannot set locale");
  29. else if (regcomp (&re, "[a-f]*", 0) != REG_NOERROR)
  30. puts ("cannot compile expression \"[a-f]*\"");
  31. else if (regexec (&re, "abcdefCDEF", 1, mat, 0) == REG_NOMATCH)
  32. puts ("no match");
  33. else
  34. {
  35. exitcode = mat[0].rm_so != 0 || mat[0].rm_eo != 6;
  36. printf ("match from %d to %d - %s\n",
  37. mat[0].rm_so, mat[0].rm_eo,
  38. exitcode ? "WRONG!" : "ok"
  39. );
  40. }
  41. return exitcode;
  42. #else
  43. return 23;
  44. #endif
  45. }