Beispiel #1
0
Datei: b_cd.c Projekt: Selk/Dev
void			b_cd(t_struct *val)
{
	struct stat		pathstat;
	char			*pwd;

	if (cd_test(val) < 0)
		return ;
	if (!val->cmd_array[1] || ft_strcmp(val->cmd_array[1], "~") == 0)
		cd(val, "HOME=", 4);
	else if (ft_strcmp(val->cmd_array[1], "-") == 0)
		cd(val, "OLDPWD=", 6);
	else if (stat(val->cmd_array[1], &pathstat) < 0)
		ft_printf("cd : no such file or directory: %s\n", val->cmd_array[1]);
	else if (!(S_ISDIR(pathstat.st_mode)))
		ft_printf("cd : not a directory: %s\n", val->cmd_array[1]);
	else if (!(pathstat.st_mode & S_IXUSR))
		ft_printf("cd : permission denied: %s\n", val->cmd_array[1]);
	else
	{
		chdir(val->cmd_array[1]);
		pwd = NULL;
		pwd = getcwd(pwd, BUFF_SIZE);
		put_oldpwd(put_pwd(pwd, val), val);
		free(pwd);
	}
}
Beispiel #2
0
int	my_cd_access(t_info *info, char **tab)
{
  if (access(tab[1], F_OK) != -1)
    {
      if (access(tab[1], R_OK) != -1)
	{
	  if (chdir(tab[1]) == -1)
	    {
	      my_printf("%E", "Error for use chdir (change directory)\n");
	      return (EXIT_FAILURE);
	    }
	  else
	    put_pwd(info);
	}
      else
	{
	  my_printf("%E%E", tab[1], ": Permission denied.\n");
	  return (EXIT_FAILURE);
	}
    }
  else
    {
      my_printf("%E%E", tab[1], ": No such file or directory.\n");
      return (EXIT_FAILURE);
    }
  info->last_status = EXIT_SUCCESS;
  return (EXIT_SUCCESS);
}
Beispiel #3
0
Datei: b_cd.c Projekt: Selk/Dev
static void		cd(t_struct *val, char *type, int flag)
{
	int		i;
	char	*tmp;

	i = 0;
	while (val->env[i])
	{
		if (ft_strstr(val->env[i], type) && val->env[i][flag] == '=')
		{
			tmp = get_tmp(ft_strstr(val->env[i], type));
			if (ft_strcmp(type, "OLDPWD=") == 0)
				ft_printf("%s\n", tmp);
			chdir(tmp);
			put_oldpwd(put_pwd(tmp, val), val);
			free(tmp);
		}
		i++;
	}
}