- return (filename_ncmp (dir, filename, dir_len) == 0
- && (IS_DIR_SEPARATOR (filename[dir_len])
- || filename[dir_len] == '\0'));
+ for (;;)
+ {
+ /* Trim trailing slashes ("/"). PATTERN also has slashes trimmed the
+ same way so they will match. */
+ while (filename_len && IS_DIR_SEPARATOR (filename[filename_len - 1]))
+ filename_len--;
+ filename[filename_len] = '\0';
+ if (filename_len == 0)
+ {
+ if (debug_auto_load)
+ fprintf_unfiltered (gdb_stdlog,
+ _("auto-load: Not matched - pattern \"%s\".\n"),
+ pattern);
+ return 0;
+ }
+
+ if (gdb_filename_fnmatch (pattern, filename, FNM_FILE_NAME | FNM_NOESCAPE)
+ == 0)
+ {
+ if (debug_auto_load)
+ fprintf_unfiltered (gdb_stdlog, _("auto-load: Matched - file "
+ "\"%s\" to pattern \"%s\".\n"),
+ filename, pattern);
+ return 1;
+ }
+
+ /* Trim trailing FILENAME component. */
+ while (filename_len > 0 && !IS_DIR_SEPARATOR (filename[filename_len - 1]))
+ filename_len--;
+ }
+}
+
+/* Return 1 if FILENAME matches PATTERN or if FILENAME resides in
+ a subdirectory of a directory that matches PATTERN. Return 0 otherwise.
+ gdb_realpath normalization is never done here. */
+
+static ATTRIBUTE_PURE int
+filename_is_in_pattern (const char *filename, const char *pattern)
+{
+ char *filename_copy, *pattern_copy;
+
+ filename_copy = alloca (strlen (filename) + 1);
+ strcpy (filename_copy, filename);
+ pattern_copy = alloca (strlen (pattern) + 1);
+ strcpy (pattern_copy, pattern);
+
+ return filename_is_in_pattern_1 (filename_copy, pattern_copy);