| 654 | } glob; |
| 655 | |
| 656 | static void glob_match(char *arg, int abpos, int fbpos) |
| 657 | { |
| 658 | int len; |
| 659 | char *slash; |
| 660 | |
| 661 | while (*arg == '.' && arg[1] == '/') { |
| 662 | if (fbpos < 0) { |
| 663 | ENSURE_MEMSPACE(glob.filt_buf, char, glob.fbsize, glob.absize); |
| 664 | memcpy(glob.filt_buf, glob.arg_buf, abpos + 1); |
| 665 | fbpos = abpos; |
| 666 | } |
| 667 | ENSURE_MEMSPACE(glob.arg_buf, char, glob.absize, abpos + 3); |
| 668 | glob.arg_buf[abpos++] = *arg++; |
| 669 | glob.arg_buf[abpos++] = *arg++; |
| 670 | glob.arg_buf[abpos] = '\0'; |
| 671 | } |
| 672 | if ((slash = strchr(arg, '/')) != NULL) { |
| 673 | *slash = '\0'; |
| 674 | len = slash - arg; |
| 675 | } else |
| 676 | len = strlen(arg); |
| 677 | if (strpbrk(arg, "*?[")) { |
| 678 | struct dirent *di; |
| 679 | DIR *d; |
| 680 | |
| 681 | if (!(d = opendir(abpos ? glob.arg_buf : "."))) |
| 682 | return; |
| 683 | while ((di = readdir(d)) != NULL) { |
| 684 | char *dname = d_name(di); |
| 685 | if (dname[0] == '.' && (dname[1] == '\0' |
| 686 | || (dname[1] == '.' && dname[2] == '\0'))) |
| 687 | continue; |
| 688 | if (!wildmatch(arg, dname)) |
| 689 | continue; |
| 690 | call_glob_match(dname, strlen(dname), 1, |
| 691 | slash ? arg + len + 1 : NULL, |
| 692 | abpos, fbpos); |
| 693 | } |
| 694 | closedir(d); |
| 695 | } else { |
| 696 | call_glob_match(arg, len, 0, |
| 697 | slash ? arg + len + 1 : NULL, |
| 698 | abpos, fbpos); |
| 699 | } |
| 700 | if (slash) |
| 701 | *slash = '/'; |
| 702 | } |
| 703 | |
| 704 | static inline void call_glob_match(const char *name, int len, int from_glob, |
| 705 | char *arg, int abpos, int fbpos) |
no test coverage detected