[PATCH] ash: improve / fix glob expansion
Denys Vlasenko
vda.linux at googlemail.com
Tue Jan 31 21:09:10 UTC 2017
>> I plan to massage it into this - do you see any bugs?
> Looks okay.
I'm committing this version, yell if something wrong.
hasmeta(const char *p)
{
static const char chars[] ALIGN1 = {
'*', '?', '[', '\\', CTLQUOTEMARK, CTLESC, 0
};
for (;;) {
p = strpbrk(p, chars);
if (!p)
break;
switch ((unsigned char) *p) {
case CTLQUOTEMARK:
for (;;) {
p++;
if (*p == CTLQUOTEMARK)
break;
if (*p == CTLESC)
p++;
if (*p == '\0') /* huh? */
return 0;
}
break;
case '\\':
case CTLESC:
p++;
if (*p == '\0')
return 0;
break;
case '[':
if (!strchr(p + 1, ']')) {
/* It's not a properly closed [] pattern,
* but other metas may follow.
Continue checking.
* my[file* _is_ globbed by bash
* and matches filenames like "my[file1".
*/
break;
}
/* fallthrough */
default:
/* case '*': */
/* case '?': */
return 1;
}
p++;
}
return 0;
More information about the busybox
mailing list