]> git.ipfire.org Git - thirdparty/glibc.git/blame - misc/regexp.c
Remove "Contributed by" lines
[thirdparty/glibc.git] / misc / regexp.c
CommitLineData
1c70b6f1 1/* Compatibility symbols for the obsolete <regexp.h> interface.
2b778ceb 2 Copyright (C) 1996-2021 Free Software Foundation, Inc.
84384f5b 3 This file is part of the GNU C Library.
84384f5b
UD
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
84384f5b
UD
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
84384f5b 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
84384f5b 18
1c70b6f1
ZW
19/* regexp.h now contains only an #error directive, so it cannot be
20 used in this file.
21
22 The function that would produce an 'expbuf' to use as the second
23 argument to 'step' and 'advance' was defined only in regexp.h,
24 as its definition depended on macros defined by the user. */
2ec11c2b
ZW
25
26#include <regex.h>
1c70b6f1
ZW
27#include <shlib-compat.h>
28
29#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_23)
84384f5b 30
7c241325
FW
31/* Define the variables used for the interface. */
32char *loc1;
33char *loc2;
1c70b6f1
ZW
34compat_symbol (libc, loc1, loc1, GLIBC_2_0);
35compat_symbol (libc, loc2, loc2, GLIBC_2_0);
84384f5b
UD
36
37/* Although we do not support the use we define this variable as well. */
7c241325 38char *locs;
1c70b6f1 39compat_symbol (libc, locs, locs, GLIBC_2_0);
84384f5b
UD
40
41
42/* Find the next match in STRING. The compiled regular expression is
43 found in the buffer starting at EXPBUF. `loc1' will return the
44 first character matched and `loc2' points to the next unmatched
45 character. */
46int
1c70b6f1
ZW
47weak_function attribute_compat_text_section
48step (const char *string, const char *expbuf)
84384f5b
UD
49{
50 regmatch_t match; /* We only need info about the full match. */
51
52 expbuf += __alignof (regex_t *);
53 expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
54
49f3a758 55 if (__regexec ((const regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
84384f5b
UD
56 == REG_NOMATCH)
57 return 0;
58
59 loc1 = (char *) string + match.rm_so;
60 loc2 = (char *) string + match.rm_eo;
61 return 1;
62}
1c70b6f1 63compat_symbol (libc, step, step, GLIBC_2_0);
84384f5b
UD
64
65
66/* Match the beginning of STRING with the compiled regular expression
67 in EXPBUF. If the match is successful `loc2' will contain the
68 position of the first unmatched character. */
69int
1c70b6f1
ZW
70weak_function attribute_compat_text_section
71advance (const char *string, const char *expbuf)
84384f5b
UD
72{
73 regmatch_t match; /* We only need info about the full match. */
74
75 expbuf += __alignof__ (regex_t *);
76 expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
77
49f3a758 78 if (__regexec ((const regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
84384f5b
UD
79 == REG_NOMATCH
80 /* We have to check whether the check is at the beginning of the
81 buffer. */
82 || match.rm_so != 0)
83 return 0;
84
85 loc2 = (char *) string + match.rm_eo;
86 return 1;
87}
1c70b6f1
ZW
88compat_symbol (libc, advance, advance, GLIBC_2_0);
89
90
91#endif /* SHLIB_COMPAT (2.0, 2.23) */