regexp.c 3.0 KB

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