Пример #1
0
void	long_list_format_file(t_d *d, char *path)
{
	t_stat	stat;
	char	c_type;

	c_type = type_file_file(&stat, path);
	ft_putchar(c_type);
	left_side_file(&stat);
	ft_putchar(' ');
	if (c_type == 'c' || c_type == 'b')
		major_minor_file(&stat);
	else
	{
		display_size_file(d, stat);
	}
	get_time_file(stat);
	print_elem_in_color_file(stat, path, c_type);
	read_link_file(path, c_type);
	ft_putchar('\n');
	return ;
}
Пример #2
0
int main(int argc, char *argv[])
{
	char *env;
	int i, n, timeout = 250;
	struct connection *conn;

	method = "HEAD";

	while ((i = getopt(argc, argv, "hp:t:vT:")) != -1)
		switch ((char)i) {
		case 'h':
			usage(0);
		case 'p':
			set_proxy(optarg);
			break;
		case 't':
			thread_limit = strtol(optarg, NULL, 0);
			break;
		case 'v':
			verbose++;
			break;
		case 'T':
			read_timeout = strtol(optarg, NULL, 0);
			break;
		default:
			usage(1);
		}

	if (optind < argc)
		while (optind < argc)
			read_link_file(argv[optind++]);
	else
		read_urls(stdin);

	/* set_proxy will not use this if proxy already set */
	env = getenv("COMICS_PROXY");
	if (env)
		set_proxy(env);

	if (thread_limit == 0) {
		printf("You must allow at least one thread\n");
		exit(1);
	}

	if (thread_limit > n_comics)
		thread_limit = n_comics;

#ifdef _WIN32
	win32_init();
#else
	signal(SIGTERM, dump_outstanding);
	signal(SIGHUP, dump_outstanding);
#endif

	npoll = thread_limit + 1; /* add one for stdin */
	ufds = must_calloc(npoll, sizeof(struct pollfd));
	for (i = 0; i < npoll; ++i)
		ufds[i].fd = -1;

	while (head || outstanding) {

		start_next_comic();

		n = poll(ufds, npoll, timeout);
		if (n < 0) {
			my_perror("poll");
			continue;
		}

		if (n == 0) {
			timeout_connections();
			if (!start_next_comic())
				/* Once we have all the comics
				 * started, increase the timeout
				 * period. */
				timeout = 1000;
			continue;
		}

		for (conn = comics; conn; conn = conn->next)
			if (!conn->poll)
				continue;
			else if (conn->poll->revents & POLLOUT) {
				if (!conn->connected)
					check_connect(conn);
				else {
					time(&conn->access);
					write_request(conn);
				}
			} else if (conn->poll->revents & POLLIN) {
				/* This check is needed for openssl */
				if (!conn->connected)
					check_connect(conn);
				else
					read_conn(conn);
			}
	}

	out_results(comics, 0);

	return n_comics != gotit;
}