regexp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Compatibility symbols for the obsolete <regexp.h> interface.
  2. Copyright (C) 1996-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. /* regexp.h now contains only an #error directive, so it cannot be
  17. used in this file.
  18. The function that would produce an 'expbuf' to use as the second
  19. argument to 'step' and 'advance' was defined only in regexp.h,
  20. as its definition depended on macros defined by the user. */
  21. #include <regex.h>
  22. #include <shlib-compat.h>
  23. #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_23)
  24. /* Define the variables used for the interface. Avoid .symver on common
  25. symbol, which just creates a new common symbol, not an alias. */
  26. char *loc1 __attribute__ ((nocommon));
  27. char *loc2 __attribute__ ((nocommon));
  28. compat_symbol (libc, loc1, loc1, GLIBC_2_0);
  29. compat_symbol (libc, loc2, loc2, GLIBC_2_0);
  30. /* Although we do not support the use we define this variable as well. */
  31. char *locs __attribute__ ((nocommon));
  32. compat_symbol (libc, locs, locs, GLIBC_2_0);
  33. /* Find the next match in STRING. The compiled regular expression is
  34. found in the buffer starting at EXPBUF. `loc1' will return the
  35. first character matched and `loc2' points to the next unmatched
  36. character. */
  37. int
  38. weak_function attribute_compat_text_section
  39. step (const char *string, const char *expbuf)
  40. {
  41. regmatch_t match; /* We only need info about the full match. */
  42. expbuf += __alignof (regex_t *);
  43. expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
  44. if (__regexec ((const regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
  45. == REG_NOMATCH)
  46. return 0;
  47. loc1 = (char *) string + match.rm_so;
  48. loc2 = (char *) string + match.rm_eo;
  49. return 1;
  50. }
  51. compat_symbol (libc, step, step, GLIBC_2_0);
  52. /* Match the beginning of STRING with the compiled regular expression
  53. in EXPBUF. If the match is successful `loc2' will contain the
  54. position of the first unmatched character. */
  55. int
  56. weak_function attribute_compat_text_section
  57. advance (const char *string, const char *expbuf)
  58. {
  59. regmatch_t match; /* We only need info about the full match. */
  60. expbuf += __alignof__ (regex_t *);
  61. expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
  62. if (__regexec ((const regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
  63. == REG_NOMATCH
  64. /* We have to check whether the check is at the beginning of the
  65. buffer. */
  66. || match.rm_so != 0)
  67. return 0;
  68. loc2 = (char *) string + match.rm_eo;
  69. return 1;
  70. }
  71. compat_symbol (libc, advance, advance, GLIBC_2_0);
  72. #endif /* SHLIB_COMPAT (2.0, 2.23) */