コード例 #1
0
ファイル: func_my_cd.c プロジェクト: girards/42sh
int		cd_tild(char **args, t_dlist *env, t_cmd *cmd, int i)
{
  char		*path;

  path = get_path_from_opt(args[1]);
  if (check_access(env, cmd, i) == -1)
    return (-1);
  chdir(get_my_home(env));
  if (strcmp(path, "\0") == 0)
    {
      modif_oldpwd(get_env("PWD", env), env);
      modif_pwd_from_home_to_path(args[1], env);
      return (0);
    }
  path = realloc_path(path, env);
  if (access(path, F_OK) == -1 || access(path, R_OK) == -1)
    {
      if (access(path, F_OK) == -1)
	fprintf(stderr, "42sh: cd: No such file or directory\n");
      else
	print_permission_denied(cmd, i);
      return (-1);
    }
  chdir(path);
  modif_oldpwd(get_env("PWD", env), env);
  modif_pwd_from_home_to_path(args[1], env);
  return (0);
}
コード例 #2
0
ファイル: cmd.c プロジェクト: agadiffe/ft_sh
void			handle_cmds(t_state *state, char *line, char **cmds)
{
	if (check_builtins(state, cmds[0]))
		run_builtins(state, cmds, line);
	else if (!is_exist_cmd(state->pwd))
		print_no_such_file_or_dir(state, cmds[0], state->pwd);
	else if (!is_exec_cmd(state->pwd))
		print_permission_denied(state, cmds[0], state->pwd);
	else
		handle_validated_cmd(state, cmds);
}
コード例 #3
0
ファイル: func_my_cd.c プロジェクト: girards/42sh
int		cd_dash(t_dlist *env, t_cmd *cmd, int i)
{
  if (access(get_old_pwd(env), F_OK) == -1
      || access(get_old_pwd(env), R_OK) == -1)
    {
      if (access(get_old_pwd(env), F_OK) == -1)
        fprintf(stderr, "42sh: cd: No such file or directory.\n");
      else
	print_permission_denied(cmd, i);
      return (-1);
    }
  chdir(get_old_pwd(env));
  modif_oldpwd(get_old_pwd(env), env);
  return (0);
}
コード例 #4
0
ファイル: builtins_cd.c プロジェクト: agadiffe/ft_sh
static void		handle_cd_to(t_state *state, char *cd_to)
{
    struct stat		statt;

    if (!is_exist_cmd(cd_to))
        print_no_such_file_or_dir(state, "cd", cd_to);
    else if (stat(cd_to, &statt) && !S_ISDIR(statt.st_mode))
        print_not_a_directory(state, "cd", cd_to);
    else if (!is_exec_cmd(cd_to))
        print_permission_denied(state, "cd", cd_to);
    else
    {
        set_oldpwd(state);
        set_pwd(state, cd_to);
    }
}