Exemplo n.º 1
0
static int	build_stats(t_item *link, t_args *args)
{
	int	ret;

	ret = 2;
	link->stats = NULL;
	if ((link->stats = (struct stat *)malloc(sizeof(struct stat))))
	{
		if (args->options->l == 1 || args->options->t == 1 ||
				args->options->re == 1)
		{
			if ((ret = lstat(link->path, link->stats)) != 0)
				cannot_access(link, args);
		}
		else
		{
			if ((ret = stat(link->path, link->stats)) != 0)
			{
				if ((ret = lstat(link->path, link->stats)) != 0)
					cannot_access(link, args);
			}
		}
	}
	else
		not_enough_memory(args);
	return (ret);
}
Exemplo n.º 2
0
int	m_cd(t_data *data)
{
  char	*pwd_asked;
  char	*start_pwd;
  int	ret;
  bool	go_home;

  if (data->env == NULL || data->env[0] == NULL || data->env[1] == NULL)
    return (0);
  go_home = false;
  pwd_asked = data->cmd[1];
  pwd_asked = set_home(data, &go_home, pwd_asked);
  if (data->old_pwd == NULL && pwd_asked[0] == '-')
    return (0);
  if (pwd_asked[0] == '-')
    pwd_asked = data->old_pwd;
  data->old_pwd = my_strdup(&data->pwd[4]);
  ret = chdir(pwd_asked);
  if (ret == 0)
    {
      start_pwd = data->pwd;
      change_path(data, pwd_asked, start_pwd, go_home);
    }
  else
    cannot_access(pwd_asked);
  return (0);
}