+ sysgdbinit.push_back (relocated_sysgdbinit);
+ }
+ if (SYSTEM_GDBINIT_DIR[0])
+ {
+ std::string relocated_gdbinit_dir
+ = relocate_gdbinit_path_maybe_in_datadir
+ (SYSTEM_GDBINIT_DIR, SYSTEM_GDBINIT_DIR_RELOCATABLE);
+ if (!relocated_gdbinit_dir.empty ()) {
+ gdb_dir_up dir (opendir (relocated_gdbinit_dir.c_str ()));
+ if (dir != nullptr)
+ {
+ std::vector<std::string> files;
+ for (;;)
+ {
+ struct dirent *ent = readdir (dir.get ());
+ if (ent == nullptr)
+ break;
+ std::string name (ent->d_name);
+ if (name == "." || name == "..")
+ continue;
+ /* ent->d_type is not available on all systems (e.g. mingw,
+ Solaris), so we have to call stat(). */
+ std::string filename
+ = relocated_gdbinit_dir + SLASH_STRING + name;
+ if (stat (filename.c_str (), &s) != 0
+ || !S_ISREG (s.st_mode))
+ continue;
+ const struct extension_language_defn *extlang
+ = get_ext_lang_of_file (filename.c_str ());
+ /* We effectively don't support "set script-extension
+ off/soft", because we are loading system init files here,
+ so it does not really make sense to depend on a
+ setting. */
+ if (extlang != nullptr && ext_lang_present_p (extlang))
+ files.push_back (std::move (filename));
+ }
+ std::sort (files.begin (), files.end ());
+ sysgdbinit.insert (sysgdbinit.end (),
+ files.begin (), files.end ());
+ }
+ }