Пример #1
0
char *
relocate_gdb_directory (const char *initial, int flag)
{
  char *dir;

  dir = relocate_path (gdb_program_name, initial, flag);
  if (dir)
    {
      struct stat s;

      if (*dir == '\0' || stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
	{
	  xfree (dir);
	  dir = NULL;
	}
    }
  if (!dir)
    dir = xstrdup (initial);

  /* Canonicalize the directory.  */
  if (*dir)
    {
      char *canon_sysroot = lrealpath (dir);

      if (canon_sysroot)
	{
	  xfree (dir);
	  dir = canon_sysroot;
	}
    }

  return dir;
}
Пример #2
0
const char *
lua_cpath_default()
{
  if (! s_cpath_default)
    {
      const char *dir = lua_executable_dir(0);
      s_cpath_default = LUA_CPATH_DEFAULT_STATIC;
      if (dir)
        s_cpath_default = relocate_path(dir, LUA_CPATH_DEFAULT_STATIC);
    }
  return s_cpath_default;
}
Пример #3
0
/* Compute the locations of init files that GDB should source and
   return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT.  If
   there is no system gdbinit (resp. home gdbinit and local gdbinit)
   to be loaded, then SYSTEM_GDBINIT (resp. HOME_GDBINIT and
   LOCAL_GDBINIT) is set to NULL.  */
static void
get_init_files (const char **system_gdbinit,
		const char **home_gdbinit,
		const char **local_gdbinit)
{
  static const char *sysgdbinit = NULL;
  static char *homeinit = NULL;
  static const char *localinit = NULL;
  static int initialized = 0;

  if (!initialized)
    {
      struct stat homebuf, cwdbuf, s;
      char *homedir;

      if (SYSTEM_GDBINIT[0])
	{
	  int datadir_len = strlen (GDB_DATADIR);
	  int sys_gdbinit_len = strlen (SYSTEM_GDBINIT);
	  char *relocated_sysgdbinit;

	  /* If SYSTEM_GDBINIT lives in data-directory, and data-directory
	     has been provided, search for SYSTEM_GDBINIT there.  */
	  if (gdb_datadir_provided
	      && datadir_len < sys_gdbinit_len
	      && filename_ncmp (SYSTEM_GDBINIT, GDB_DATADIR, datadir_len) == 0
	      && IS_DIR_SEPARATOR (SYSTEM_GDBINIT[datadir_len]))
	    {
	      /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
		 to gdb_datadir.  */
	      char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
	      char *p;

	      for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p)
		continue;
	      relocated_sysgdbinit = concat (gdb_datadir, SLASH_STRING, p,
					     (char *) NULL);
	      xfree (tmp_sys_gdbinit);
	    }
	  else
	    {
	      relocated_sysgdbinit = relocate_path (gdb_program_name,
						    SYSTEM_GDBINIT,
						    SYSTEM_GDBINIT_RELOCATABLE);
	    }
	  if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
	    sysgdbinit = relocated_sysgdbinit;
	  else
	    xfree (relocated_sysgdbinit);
	}

      homedir = getenv ("HOME");

      /* If the .gdbinit file in the current directory is the same as
	 the $HOME/.gdbinit file, it should not be sourced.  homebuf
	 and cwdbuf are used in that purpose.  Make sure that the stats
	 are zero in case one of them fails (this guarantees that they
	 won't match if either exists).  */

      memset (&homebuf, 0, sizeof (struct stat));
      memset (&cwdbuf, 0, sizeof (struct stat));

      if (homedir)
	{
	  homeinit = xstrprintf ("%s/%s", homedir, gdbinit);
	  if (stat (homeinit, &homebuf) != 0)
	    {
	      xfree (homeinit);
	      homeinit = NULL;
	    }
	}

      if (stat (gdbinit, &cwdbuf) == 0)
	{
	  if (!homeinit
	      || memcmp ((char *) &homebuf, (char *) &cwdbuf,
			 sizeof (struct stat)))
	    localinit = gdbinit;
	}
      
      initialized = 1;
    }

  *system_gdbinit = sysgdbinit;
  *home_gdbinit = homeinit;
  *local_gdbinit = localinit;
}