diff options
author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2023-04-21 04:48:59 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-04-21 12:33:39 +0200 |
commit | c775ee2259ff84bb9797e214870e5cfe74f1c070 (patch) | |
tree | 7082d363893dd8404cb393f755f5f5c30c959399 | |
parent | 7d6b0208863d41c78785c47d564cf4b55906f0d1 (diff) |
regex.3: Finalise move of reg*.3type
They're inextricably linked, not cross-referenced at all,
and not used anywhere else.
Now that they (realistically) exist to the reader, add a note
on how big nmatch can be; POSIX even says "The application developer
should note that there is probably no reason for using a value of
nmatch that is larger than preg−>re_nsub+1.".
Also remove the now-duplicate regmatch_t declaration.
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | man3/regex.3 | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/man3/regex.3 b/man3/regex.3 index 9d4b274e2..702a7645c 100644 --- a/man3/regex.3 +++ b/man3/regex.3 @@ -60,6 +60,21 @@ is a null-terminated string. The locale must be the same when running .BR regexec (). .PP +After +.BR regcomp () +succeeds, +.I preg->re_nsub +holds the number of subexpressions in +.IR regex . +Thus, a value of +.I preg->re_nsub ++ 1 +passed as +.I nmatch +to +.BR regexec () +is sufficient to capture all matches. +.PP .I cflags is the bitwise OR @@ -192,22 +207,6 @@ must be at least .IR N+1 .) Any unused structure elements will contain the value \-1. .PP -The -.I regmatch_t -structure which is the type of -.I pmatch -is defined in -.IR <regex.h> . -.PP -.in +4n -.EX -typedef struct { - regoff_t rm_so; - regoff_t rm_eo; -} regmatch_t; -.EE -.in -.PP Each .I rm_so element that is not \-1 indicates the start offset of the next largest @@ -218,7 +217,7 @@ element indicates the end offset of the match, which is the offset of the first character after the matching text. .PP .I regoff_t -It is a signed integer type +is a signed integer type capable of storing the largest value that can be stored in either an .I ptrdiff_t type or a @@ -348,12 +347,27 @@ POSIX.1-2008. POSIX.1-2001. .PP Prior to POSIX.1-2008, -the type was +.I regoff_t +was required to be capable of storing the largest value that can be stored in either an .I off_t type or a .I ssize_t type. +.SH CAVEATS +.I re_nsub +is only required to be initialized if +.B REG_NOSUB +wasn't specified, but all known implementations initialize it regardless. +.\" glibc, musl, 4.4BSD, illumos +.PP +Both +.I regex_t +and +.I regmatch_t +may (and do) have more members, in any order. +Always reference them by name. +.\" illumos has two more start/end pairs and the first one is of pointers .SH EXAMPLES .EX #include <stdint.h> |