+/* Return 1 if DNAME should be skipped according to PAT. Mostly concerned
+ with matching leading `.'. */
+
+static int
+skipname (pat, dname)
+ char *pat;
+ char *dname;
+{
+ /* If a leading dot need not be explicitly matched, and the pattern
+ doesn't start with a `.', don't match `.' or `..' */
+ if (noglob_dot_filenames == 0 && pat[0] != '.' &&
+ (pat[0] != '\\' || pat[1] != '.') &&
+ (dname[0] == '.' &&
+ (dname[1] == '\0' || (dname[1] == '.' && dname[2] == '\0'))))
+ return 1;
+
+ /* If a dot must be explicity matched, check to see if they do. */
+ else if (noglob_dot_filenames && dname[0] == '.' && pat[0] != '.' &&
+ (pat[0] != '\\' || pat[1] != '.'))
+ return 1;
+
+ return 0;
+}
+
+#if HANDLE_MULTIBYTE
+/* Return 1 if DNAME should be skipped according to PAT. Handles multibyte
+ characters in PAT and DNAME. Mostly concerned with matching leading `.'. */
+
+static int
+mbskipname (pat, dname)
+ char *pat, *dname;
+{
+ char *pat_bak, *dn_bak;
+ wchar_t *pat_wc, *dn_wc;
+ mbstate_t pat_ps, dn_ps;
+ size_t pat_n, dn_n, n;
+
+ n = strlen(pat);
+ pat_bak = (char *) alloca (n + 1);
+ memcpy (pat_bak, pat, n + 1);
+
+ n = strlen(dname);
+ dn_bak = (char *) alloca (n + 1);
+ memcpy (dn_bak, dname, n + 1);
+
+ memset(&pat_ps, '\0', sizeof(mbstate_t));
+ memset(&dn_ps, '\0', sizeof(mbstate_t));
+
+ pat_n = xmbsrtowcs (NULL, (const char **)&pat_bak, 0, &pat_ps);
+ dn_n = xmbsrtowcs (NULL, (const char **)&dn_bak, 0, &dn_ps);
+
+ if (pat_n != (size_t)-1 && dn_n !=(size_t)-1)
+ {
+ pat_wc = (wchar_t *) alloca ((pat_n + 1) * sizeof(wchar_t));
+ dn_wc = (wchar_t *) alloca ((dn_n + 1) * sizeof(wchar_t));
+
+ (void) xmbsrtowcs (pat_wc, (const char **)&pat_bak, pat_n + 1, &pat_ps);
+ (void) xmbsrtowcs (dn_wc, (const char **)&dn_bak, dn_n + 1, &dn_ps);
+
+ /* If a leading dot need not be explicitly matched, and the
+ pattern doesn't start with a `.', don't match `.' or `..' */
+ if (noglob_dot_filenames == 0 && pat_wc[0] != L'.' &&
+ (pat_wc[0] != L'\\' || pat_wc[1] != L'.') &&
+ (dn_wc[0] == L'.' &&
+ (dn_wc[1] == L'\0' || (dn_wc[1] == L'.' && dn_wc[2] == L'\0'))))
+ return 1;
+
+ /* If a leading dot must be explicity matched, check to see if the
+ pattern and dirname both have one. */
+ else if (noglob_dot_filenames && dn_wc[0] == L'.' &&
+ pat_wc[0] != L'.' &&
+ (pat_wc[0] != L'\\' || pat_wc[1] != L'.'))
+ return 1;
+ }
+
+ return 0;