Пример #1
0
std::string
get_standard_cache_dir ()
{
#ifdef __APPLE__
#define HOME_CACHE_DIR "Library/Caches"
#else
#define HOME_CACHE_DIR ".cache"
#endif

#ifndef __APPLE__
  const char *xdg_cache_home = getenv ("XDG_CACHE_HOME");
  if (xdg_cache_home != NULL)
    {
      /* Make sure the path is absolute and tilde-expanded.  */
      gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (xdg_cache_home));
      return string_printf ("%s/gdb", abs.get ());
    }
#endif

  const char *home = getenv ("HOME");
  if (home != NULL)
    {
      /* Make sure the path is absolute and tilde-expanded.  */
      gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (home));
      return string_printf ("%s/" HOME_CACHE_DIR "/gdb", abs.get ());
    }

  return {};
}
Пример #2
0
void
set_gdb_data_directory (const char *new_datadir)
{
  struct stat st;

  if (stat (new_datadir, &st) < 0)
    {
      int save_errno = errno;

      fprintf_unfiltered (gdb_stderr, "Warning: ");
      print_sys_errmsg (new_datadir, save_errno);
    }
  else if (!S_ISDIR (st.st_mode))
    warning (_("%s is not a directory."), new_datadir);

  xfree (gdb_datadir);
  gdb_datadir = gdb_realpath (new_datadir);

  /* gdb_realpath won't return an absolute path if the path doesn't exist,
     but we still want to record an absolute path here.  If the user entered
     "../foo" and "../foo" doesn't exist then we'll record $(pwd)/../foo which
     isn't canonical, but that's ok.  */
  if (!IS_ABSOLUTE_PATH (gdb_datadir))
    {
      char *abs_datadir = gdb_abspath (gdb_datadir);

      xfree (gdb_datadir);
      gdb_datadir = abs_datadir;
    }
}