diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/regex.h | 4 | ||||
-rw-r--r-- | posix/regexec.c | 20 |
2 files changed, 19 insertions, 5 deletions
diff --git a/posix/regex.h b/posix/regex.h index b4a975b48b..4279dbcc5b 100644 --- a/posix/regex.h +++ b/posix/regex.h @@ -298,6 +298,10 @@ extern reg_syntax_t re_syntax_options; /* Like REG_NOTBOL, except for the end-of-line. */ #define REG_NOTEOL (1 << 1) +/* Use PMATCH[0] to delimit the start and end of the search in the + buffer. */ +#define REG_STARTEND (1 << 2) + /* If any error codes are removed, changed, or added, update the `re_error_msg' table in regex.c. */ diff --git a/posix/regexec.c b/posix/regexec.c index cad676c0fe..09142c5f7a 100644 --- a/posix/regexec.c +++ b/posix/regexec.c @@ -215,13 +215,23 @@ regexec (preg, string, nmatch, pmatch, eflags) int eflags; { reg_errcode_t err; - int length = strlen (string); + int start, length; + if (eflags & REG_STARTEND) + { + start = pmatch[0].rm_so; + length = pmatch[0].rm_eo; + } + else + { + start = 0; + length = strlen (string); + } if (preg->no_sub) - err = re_search_internal (preg, string, length, 0, length, length, 0, - NULL, eflags); + err = re_search_internal (preg, string, length, start, length - start, + length, 0, NULL, eflags); else - err = re_search_internal (preg, string, length, 0, length, length, nmatch, - pmatch, eflags); + err = re_search_internal (preg, string, length, start, length - start, + length, nmatch, pmatch, eflags); return err != REG_NOERROR; } #ifdef _LIBC |