#include<iostream>
/*****************************************************************************************
Function: CopyFile
Description: 复制文件
Input: pSrc:原文件路径 pDes:复制后的文件路径
Return: >0:成功 <0:失败
******************************************************************************************/
int copyFile(const char * pSrc, const char *pDes)
{
FILE *in_file, *out_file;
char data[BUF_SIZE];
size_t bytes_in, bytes_out;
long len = 0;
if ((in_file = fopen(pSrc, "rb")) == NULL)
{
perror(pSrc);
return -2;
}
if ((out_file = fopen(pDes, "wb")) == NULL)
{
perror(pDes);
return -3;
}
while ((bytes_in = fread(data, 1, BUF_SIZE, in_file)) > 0)
{
bytes_out = fwrite(data, 1, bytes_in, out_file);
if (bytes_in != bytes_out)
{
perror("Fatal write error.\n");
return -4;
}
len += bytes_out;
printf("copying file .... %d bytes copy\n", len);
}
fclose(in_file);
fclose(out_file);
remove(pSrc);
return 1;
}