mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
LibRegex+LibC: Make re_nsub available to the user
To comply with Dr.POSIX, this field has to be user-accessible.
This commit is contained in:
parent
7e98457937
commit
f9fed0b167
2 changed files with 4 additions and 3 deletions
|
@ -15,6 +15,8 @@ typedef ssize_t regoff_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void* __data;
|
void* __data;
|
||||||
|
// Number of capture groups, Dr.POSIX requires this.
|
||||||
|
size_t re_nsub;
|
||||||
} regex_t;
|
} regex_t;
|
||||||
|
|
||||||
enum __Regex_Error {
|
enum __Regex_Error {
|
||||||
|
|
|
@ -26,7 +26,6 @@ struct internal_regex_t {
|
||||||
size_t re_pat_errpos;
|
size_t re_pat_errpos;
|
||||||
ReError re_pat_err;
|
ReError re_pat_err;
|
||||||
String re_pat;
|
String re_pat;
|
||||||
size_t re_nsub;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static internal_regex_t* impl_from(regex_t* re)
|
static internal_regex_t* impl_from(regex_t* re)
|
||||||
|
@ -51,7 +50,7 @@ int regcomp(regex_t* reg, const char* pattern, int cflags)
|
||||||
|
|
||||||
// Note that subsequent uses of regcomp() without regfree() _will_ leak memory
|
// Note that subsequent uses of regcomp() without regfree() _will_ leak memory
|
||||||
// This could've been prevented if libc provided a reginit() or similar, but it does not.
|
// This could've been prevented if libc provided a reginit() or similar, but it does not.
|
||||||
reg->__data = new internal_regex_t { 0, 0, {}, 0, ReError::REG_NOERR, {}, 0 };
|
reg->__data = new internal_regex_t { 0, 0, {}, 0, ReError::REG_NOERR, {} };
|
||||||
|
|
||||||
auto preg = impl_from(reg);
|
auto preg = impl_from(reg);
|
||||||
bool is_extended = cflags & REG_EXTENDED;
|
bool is_extended = cflags & REG_EXTENDED;
|
||||||
|
@ -76,7 +75,7 @@ int regcomp(regex_t* reg, const char* pattern, int cflags)
|
||||||
return (ReError)parser_result.error;
|
return (ReError)parser_result.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
preg->re_nsub = parser_result.capture_groups_count;
|
reg->re_nsub = parser_result.capture_groups_count;
|
||||||
|
|
||||||
return REG_NOERR;
|
return REG_NOERR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue