文件拷贝工具

为了便于测试透明解密的效果,写了一个文件拷贝工具,把文件从a拷贝到b位置。

//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <malloc.h>

#define TMP_BLOCK_SIZE 1024
int main(int argc, char **argv)
{
	FILE * fp_input = NULL;
	FILE * fp_output = NULL;

	char * inputname = argv[1];
	char * outputname = argv[2];

	char * tmp_buff = NULL;

	int input_file_size = 0;
	int curr_offset = 0;
	size_t i = 0;
	int ret = 0;

	tmp_buff = (char*)malloc(sizeof(char)*TMP_BLOCK_SIZE);

	ret = fopen_s(&fp_input,inputname, "rb");
	if (NULL == fp_input)
	{
		return -1;
	}
	ret = fopen_s(&fp_output,outputname, "wb");
	if (NULL == fp_output)
	{
		return -1;
	}

	_fseeki64(fp_input, 0, SEEK_END);

	input_file_size = _ftelli64(fp_input);
	if (0 == input_file_size)
	{
		// 文件大小为0
		return -1;
	}

	
	do
	{
		fseek(fp_input, curr_offset, SEEK_SET);
		if (input_file_size - curr_offset < TMP_BLOCK_SIZE)
		{
			fread(tmp_buff, 1, input_file_size - curr_offset ,fp_input);
			fwrite(tmp_buff, 1, input_file_size - curr_offset, fp_output);
		}
		else
		{
			fread(tmp_buff, 1, TMP_BLOCK_SIZE, fp_input);
			fwrite(tmp_buff, 1, TMP_BLOCK_SIZE, fp_output);

		}
		curr_offset += TMP_BLOCK_SIZE;

	} while (curr_offset <= input_file_size);

	fclose(fp_input);
	fclose(fp_output);

	if (tmp_buff != NULL)
	{
		free(tmp_buff);
		tmp_buff = NULL;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值