Exemplo n.º 1
0
char *myrealpath(char *in)
{
	char *home, *pin;
	int home_len;
	char *pout;

	if (in[0] != '~')
		return mystrdup(in);

	if (in[1] != '/')
	{
		char *user;
		char *slash = strchr(in, '/');
		int len;

		if (slash)
		{
			len = (int)((slash - in) - 1);
			pin = slash + 1;
		}
		else
		{
			len = strlen(in) - 1;
			pin = in + len + 1;
		}

		user = (char *)mymalloc(len + 1);
		memcpy(user, &in[1], len);
		user[len] = 0x00;

		home = gethome(user);

		myfree(user);
	}
	else
	{
		home = gethome(NULL);
		pin = in + 1;
	}

	if (!home)
		error_exit(FALSE, FALSE, "Cannot expand path %s:\nhome directory not found.\n", in);

	home_len = strlen(home);
	pout = (char *)mymalloc(home_len + strlen(in) + 1);

	sprintf(pout, "%s/%s", home, pin);

	myfree(home);

	return pout;
}
Exemplo n.º 2
0
// locate path
// this mimics XmGetPixmap's efforts to build a path
static string bitmapPath()
{
    static string path = "";

    if (!path.empty())
	return path;

    path = BASENAME;
    const char *xbmlangpath = getenv("XBMLANGPATH");
    if (xbmlangpath == 0)
    {
	const char *xapplresdir = getenv("XAPPLRESDIR");
	const string home = gethome();

	if (xapplresdir != 0)
	    addDefaultPaths(path, xapplresdir);
	else
	    addDefaultPaths(path, home.chars());

	path += DELIMITER + home + BASENAME;
	addDefaultPaths(path, "/usr/lib/X11");
	path += DELIMITER + "/usr/include/X11/%T/" + BASENAME;
    }
    else
	path = xbmlangpath;

    return path;
}
Exemplo n.º 3
0
void	ft_cd(char *line)
{
	int			i;
	char		*tmp;
	char		*home;

	i = 0;
	home = gethome();
	tmp = (char *)malloc(sizeof(char *) * (ft_strlen(line) + 1));
	ft_strcpy(tmp, line);
	tmp = ft_strrw(tmp);
	tmp = ft_strnshift(tmp, 3);
	i = 0;
	if (tmp[0] == '~')
	{
		tmp = ft_strnshift(tmp, 1);
		while (tmp[0] == '/')
			tmp = ft_strnshift(tmp, 1);
		home = ft_strjoin(home, "/");
		home = ft_strjoin(home, tmp);
		if (chdir(home) == -1)
			ft_putstr("No such file or directory.\n");
	}
	else if (chdir(tmp) == -1)
		ft_putstr("No such file or directory.\n");
}
Exemplo n.º 4
0
string session_state_dir()
{
    const char *ddd_state = getenv(DDD_NAME "_STATE");
    if (ddd_state != 0)
	return ddd_state;
    else
	return string(gethome()) + "/." ddd_NAME;
}
Exemplo n.º 5
0
// Create DDD state directory
static void create_session_state_dir(std::ostream& msg)
{
    // Create or find state directory
    if (!is_directory(session_state_dir()) && 
	makedir(session_state_dir(), msg, true) == 0)
    {
	// Check for DDD 2.1 `~/.dddinit' and `~/.ddd_history' files; 
	// copy them to new location if needed
	copy(string(gethome()) + "/.dddinit",
	     session_state_file(DEFAULT_SESSION), msg);
	copy(string(gethome()) + "/.ddd_history",
	     session_history_file(DEFAULT_SESSION), msg);
    }

    // Create session base directory
    if (!is_directory(session_base_dir()))
	makedir(session_base_dir(), msg);

    // Create themes directory
    if (!is_directory(session_themes_dir()))
	makedir(session_themes_dir(), msg);
}
Exemplo n.º 6
0
static void
test_make_filename_try (void)
{
  char *out;
  const char *home = gethome ();
  size_t homelen = home? strlen (home):0;

  out = make_filename_try ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", NULL);
  if (out)
    fail (0);
  else if (errno != EINVAL)
    fail (0);
  xfree (out);
  out = make_filename_try ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", "4", NULL);
  if (out)
    fail (0);
  else if (errno != EINVAL)
    fail (0);
  xfree (out);

  out = make_filename_try ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                           "1", "2", NULL);
  if (!out || strcmp (out,
                      "1/2/3/4/5/6/7/8/9/10/"
                      "1/2/3/4/5/6/7/8/9/10/"
                      "1/2/3/4/5/6/7/8/9/10/"
                      "1/2"))
    fail (0);
  xfree (out);

  out = make_filename_try ("foo", "~/bar", "baz/cde", NULL);
  if (!out || strcmp (out, "foo/~/bar/baz/cde"))
    fail (1);
  xfree (out);

  out = make_filename_try ("foo", "~/bar", "baz/cde/", NULL);
  if (!out || strcmp (out, "foo/~/bar/baz/cde/"))
    fail (1);
  xfree (out);

  out = make_filename_try ("/foo", "~/bar", "baz/cde/", NULL);
  if (!out || strcmp (out, "/foo/~/bar/baz/cde/"))
    fail (1);
  xfree (out);

  out = make_filename_try ("//foo", "~/bar", "baz/cde/", NULL);
  if (!out || strcmp (out, "//foo/~/bar/baz/cde/"))
    fail (1);
  xfree (out);

  out = make_filename_try ("", "~/bar", "baz/cde", NULL);
  if (!out || strcmp (out, "/~/bar/baz/cde"))
    fail (1);
  xfree (out);


  out = make_filename_try ("~/foo", "bar", NULL);
  if (!out)
    fail (2);
  if (home)
    {
      if (strlen (out) < homelen + 7)
        fail (2);
      if (strncmp (out, home, homelen))
        fail (2);
      if (strcmp (out+homelen, "/foo/bar"))
        fail (2);
    }
  else
    {
      if (strcmp (out, "~/foo/bar"))
        fail (2);
    }
  xfree (out);

  out = make_filename_try ("~", "bar", NULL);
  if (!out)
    fail (2);
  if (home)
    {
      if (strlen (out) < homelen + 3)
        fail (2);
      if (strncmp (out, home, homelen))
        fail (2);
      if (strcmp (out+homelen, "/bar"))
        fail (2);
    }
  else
    {
      if (strcmp (out, "~/bar"))
        fail (2);
    }
  xfree (out);
}