Esempio n. 1
0
File: b_cd.c Progetto: 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);
	}
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	int rc = 0;
	int nr_round;

	if (argc < 3) {
		usage();
		goto out;
	}

	if (strcmp(argv[1], "-n") != 0) {
		usage();
		goto out;
	}

	nr_round = atoi(argv[2]);
	if (nr_round == 0) {
		usage();
		goto out;
	}
	
	do {
		rc = unit_test(nr_round);
		if (rc != 0) {
			printf("unit_test failed.\n");
		} else {
			printf("unit_test finished with round %d.\n", nr_round);
		}
		
	} while (FALSE);

	echo_test();
	
	mkdir_test();

	ls_test();

	cd_test();

	cat_test();

	date_test();

	lsmod_test();

	null_dev_test();

	multi_processes_test();

	clear_test();

	shutdown_test();

	while (TRUE) {
		;
	}

 out:

	return rc;
}