コード例 #1
0
ファイル: ftp.c プロジェクト: Jack19881218/cavan
static int ftp_list_directory1(const char *dirpath, const char *newline)
{
	int fd;
	DIR *dp;
	int ret;
	struct dirent *ep;
	char *filename;
	char pathname[1024];
	char buff[1024];
	char *buff_end = buff + sizeof(buff);

#if FTP_DEBUG
	pr_bold_info("dirpath = `%s'", dirpath);
#endif

	dp = opendir(dirpath);
	if (dp == NULL)
	{
		pr_red_info("opendir failed");
		return -EFAULT;
	}

	fd = cavan_temp_file_open(pathname, sizeof(pathname), "cavan-ftp-XXXXXX");
	if (fd < 0)
	{
		pr_red_info("cavan_temp_file_open");
		ret = fd;
		goto out_closedir;
	}

	filename = text_path_cat(pathname, sizeof(pathname), dirpath, NULL);

	while ((ep = readdir(dp)))
	{
		char *p;

		text_copy(filename, ep->d_name);

		p = ftp_file_stat_tostring(pathname, buff, buff_end);
		if (p == NULL)
		{
			continue;
		}

		p += snprintf(p, buff_end - p, " %s%s", ep->d_name, newline);

		ret = ffile_write(fd, buff, p - buff);
		if (ret < 0)
		{
			pr_red_info("ffile_write");
			goto out_close_fd;
		}
	}

	if (lseek(fd, 0, SEEK_SET) != 0)
	{
		pr_error_info("lseek");
		ret = -EFAULT;
		goto out_close_fd;
	}

	closedir(dp);
	return fd;

out_close_fd:
	close(fd);
out_closedir:
	closedir(dp);
	return ret;
}
コード例 #2
0
ファイル: input.c プロジェクト: FuangCao/cavan
int cavan_input_event(int fd, const struct input_event *events, size_t count)
{
	return ffile_write(fd, events, sizeof(struct input_event) * count);
}
コード例 #3
0
ファイル: battery.c プロジェクト: Jack19881218/cavan
int main(int argc, char *argv[])
{
	int i;
	int ret;
	int fd_in;
	int fd_out;
	struct bmp_file_header file_hdr;

	assert(argc == 3);

	fd_in = open(argv[1], O_RDONLY | O_BINARY);
	if (fd_in < 0)
	{
		print_error("open file \"%s\"", argv[1]);
		return -1;
	}

	if (file_test(argv[2], "d") < 0)
	{
		cavan_mkdir(argv[2]);
	}

	for (i = 0; i < 10; i++)
	{
		ret = bmp_read_file_header(fd_in, &file_hdr);
		if (ret < 0)
		{
			break;
		}

		fd_out = open(format_text("%s/%d.bmp", argv[2], i), O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0777);
		if (fd_out < 0)
		{
			print_error("open target file");
			break;
		}

		ret = ffile_write(fd_out, &file_hdr, sizeof(file_hdr));
		if (ret < (int) sizeof(file_hdr))
		{
			print_error("write file header");
			goto out_close_out;
		}

		ret = ffile_ncopy(fd_in, fd_out, file_hdr.size - sizeof(file_hdr));
		if (ret < 0)
		{
			error_msg("write file");
			goto out_close_out;
		}

		close(fd_out);
	}

	ret = 0;
	goto out_close_in;
out_close_out:
	close(fd_out);
out_close_in:
	close(fd_in);

	return ret;
}