1) Add all characters from ~ expansion as protected to be not interpreted
as pattern meta chars. 2) GLOB_ERR and gl_errfunc are supposed to work only for real directories per POSIX, so don't act on missing or plain files, for ENOENT or ENOTDIR (as TODO in the code suggested). 3) Remove the hack in the manpage describing how to skip ENOENT and ENOTDIR in gl_errfunc, it is unneeded now. 4) Set errno to ENAMETOOLONG if g_Ctoc() expansion fails in g_opendir(), as in other places in the code which are wrappers around system functions.
This commit is contained in:
parent
84e633724f
commit
196d61a92b
@ -275,24 +275,10 @@ is
|
||||
.Pf non- Dv NULL ,
|
||||
.Fn glob
|
||||
calls
|
||||
.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) .
|
||||
This may be unintuitive: a pattern like
|
||||
.Ql */Makefile
|
||||
will try to
|
||||
.Xr stat 2
|
||||
.Ql foo/Makefile
|
||||
even if
|
||||
.Ql foo
|
||||
is not a directory, resulting in a
|
||||
call to
|
||||
.Fa errfunc .
|
||||
The error routine can suppress this action by testing for
|
||||
.Er ENOENT
|
||||
and
|
||||
.Er ENOTDIR ;
|
||||
.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) ,
|
||||
however, the
|
||||
.Dv GLOB_ERR
|
||||
flag will still cause an immediate
|
||||
flag will cause an immediate
|
||||
return when this happens.
|
||||
.Pp
|
||||
If
|
||||
|
@ -478,7 +478,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
|
||||
return (NULL);
|
||||
|
||||
dc = wbuf;
|
||||
for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++)
|
||||
for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++ | M_PROTECT)
|
||||
continue;
|
||||
if (*dc != EOS)
|
||||
return (NULL);
|
||||
@ -712,7 +712,8 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
|
||||
*pathend = EOS;
|
||||
|
||||
if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
|
||||
/* TODO: don't call for ENOENT or ENOTDIR? */
|
||||
if (errno == ENOENT || errno == ENOTDIR)
|
||||
return (0);
|
||||
if (pglob->gl_flags & GLOB_ERR)
|
||||
return (GLOB_ABORTED);
|
||||
if (pglob->gl_errfunc) {
|
||||
@ -937,8 +938,10 @@ g_opendir(Char *str, glob_t *pglob)
|
||||
if (*str == EOS)
|
||||
strcpy(buf, ".");
|
||||
else {
|
||||
if (g_Ctoc(str, buf, sizeof(buf)))
|
||||
if (g_Ctoc(str, buf, sizeof(buf))) {
|
||||
errno = ENAMETOOLONG;
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
|
Loading…
Reference in New Issue
Block a user