-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
options/posix: port musl regex engine #511
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#define _BSD_SOURCE | ||
#include <glob.h> | ||
#include <fnmatch.h> | ||
#include <sys/stat.h> | ||
|
@@ -18,16 +19,16 @@ struct match | |
|
||
static int append(struct match **tail, const char *name, size_t len, int mark) | ||
{ | ||
struct match *m = reinterpret_cast<struct match *>(malloc(sizeof(struct match) + len + 2)); | ||
if (!m) return -1; | ||
(*tail)->next = m; | ||
m->next = NULL; | ||
memcpy(m->name, name, len+1); | ||
struct match *new = malloc(sizeof(struct match) + len + 2); | ||
if (!new) return -1; | ||
(*tail)->next = new; | ||
new->next = NULL; | ||
memcpy(new->name, name, len+1); | ||
if (mark && len && name[len-1]!='/') { | ||
m->name[len] = '/'; | ||
m->name[len+1] = 0; | ||
new->name[len] = '/'; | ||
new->name[len+1] = 0; | ||
} | ||
*tail = m; | ||
*tail = new; | ||
return 0; | ||
} | ||
|
||
|
@@ -150,13 +151,13 @@ static int do_glob(char *buf, size_t pos, int type, char *pat, int flags, int (* | |
/* With GLOB_PERIOD, don't allow matching . or .. unless | ||
* fnmatch would match them with FNM_PERIOD rules in effect. */ | ||
if (p2 && (flags & GLOB_PERIOD) && de->d_name[0]=='.' | ||
&& (!de->d_name[1] || (de->d_name[1]=='.' && !de->d_name[2])) | ||
&& (!de->d_name[1] || de->d_name[1]=='.' && !de->d_name[2]) | ||
&& fnmatch(pat, de->d_name, fnm_flags | FNM_PERIOD)) | ||
continue; | ||
|
||
memcpy(buf+pos, de->d_name, l+1); | ||
if (p2) *p2 = saved_sep; | ||
int r = do_glob(buf, pos+l, de->d_type, p2 ? p2 : const_cast<char *>(""), flags, errfunc, tail); | ||
int r = do_glob(buf, pos+l, de->d_type, p2 ? p2 : "", flags, errfunc, tail); | ||
if (r) { | ||
closedir(dir); | ||
return r; | ||
|
@@ -171,7 +172,7 @@ static int do_glob(char *buf, size_t pos, int type, char *pat, int flags, int (* | |
return 0; | ||
} | ||
|
||
static int ignore_err(const char *, int) | ||
static int ignore_err(const char *path, int err) | ||
{ | ||
return 0; | ||
} | ||
|
@@ -223,14 +224,14 @@ static int expand_tilde(char **pat, char *buf, size_t *pos) | |
return 0; | ||
} | ||
|
||
int glob(const char *__restrict pat, int flags, int (*errfunc)(const char *path, int err), glob_t *__restrict g) | ||
int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, int err), glob_t *restrict g) | ||
{ | ||
struct match head = { .next = NULL }, *tail = &head; | ||
size_t cnt, i; | ||
size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0; | ||
int error = 0; | ||
char buf[PATH_MAX]; | ||
|
||
if (!errfunc) errfunc = ignore_err; | ||
|
||
if (!(flags & GLOB_APPEND)) { | ||
|
@@ -256,7 +257,7 @@ int glob(const char *__restrict pat, int flags, int (*errfunc)(const char *path, | |
freelist(&head); | ||
return error; | ||
} | ||
|
||
for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++); | ||
if (!cnt) { | ||
if (flags & GLOB_NOCHECK) { | ||
|
@@ -269,15 +270,15 @@ int glob(const char *__restrict pat, int flags, int (*errfunc)(const char *path, | |
} | ||
|
||
if (flags & GLOB_APPEND) { | ||
char **pathv = reinterpret_cast<char **>(realloc(g->gl_pathv, (offs + g->gl_pathc + cnt + 1) * sizeof(char *))); | ||
char **pathv = realloc(g->gl_pathv, (offs + g->gl_pathc + cnt + 1) * sizeof(char *)); | ||
if (!pathv) { | ||
freelist(&head); | ||
return GLOB_NOSPACE; | ||
} | ||
g->gl_pathv = pathv; | ||
offs += g->gl_pathc; | ||
} else { | ||
g->gl_pathv = reinterpret_cast<char **>(malloc((offs + cnt + 1) * sizeof(char *))); | ||
g->gl_pathv = malloc((offs + cnt + 1) * sizeof(char *)); | ||
if (!g->gl_pathv) { | ||
freelist(&head); | ||
return GLOB_NOSPACE; | ||
|
@@ -292,7 +293,7 @@ int glob(const char *__restrict pat, int flags, int (*errfunc)(const char *path, | |
|
||
if (!(flags & GLOB_NOSORT)) | ||
qsort(g->gl_pathv+offs, cnt, sizeof(char *), sort); | ||
|
||
return error; | ||
} | ||
|
||
|
@@ -305,3 +306,6 @@ void globfree(glob_t *g) | |
g->gl_pathc = 0; | ||
g->gl_pathv = NULL; | ||
} | ||
|
||
// weak_alias(glob, glob64); | ||
// weak_alias(globfree, globfree64); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need these? |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just simply remove this?