- const char *homedir = getenv ("HOME");
-
- if (homedir == NULL)
- homedir = "$HOME";
- std::string homeinit = string_printf ("%s/%s", homedir, GDBINIT);
+ /* Find the existing home directory config file. */
+ struct stat buf;
+ std::string home_config = find_gdb_home_config_file (GDBINIT, &buf);
+ if (home_config.empty ())
+ {
+ /* The user doesn't have an existing home directory config file,
+ so we should suggest a suitable path for them to use. */
+ std::string config_dir_file
+ = get_standard_config_filename (GDBINIT);
+ if (!config_dir_file.empty ())
+ home_config = config_dir_file;
+ else
+ {
+ const char *homedir = getenv ("HOME");
+ if (homedir == nullptr)
+ homedir = "$HOME";
+ home_config = (std::string (homedir) + SLASH_STRING
+ + std::string (GDBINIT));
+ }
+ }