Linux ,c/c++, web,前端,php,js
分类:
2012-02-10 15:51:19
原文地址:文件合并程序c 作者:gududesiling
/****************INCLUDE********************/
#include
#include
#include
/****************DEFINE*********************/
#define OFFSET 0x70000
/****************FUNCTION*******************/
unsigned int getfilesize(char *file)
{
unsigned int result;
struct stat buf;
result = stat(file,&buf);
if(result == 0){
return buf.st_size;
}else{
return 0;
}
}
int main(unsigned int argc,char **argv)
{
FILE *soc_file1,*soc_file2,*dest_file;
long count = 0;
unsigned char tmp;
unsigned char *SrcFile1,*SrcFile2,*DstFile;
unsigned long offset;
unsigned long currpos;
if(argc<4){
printf("Usage:CombineBin a.bin b.bin c.bin offset or Usage:CombineBin a.bin b.bin c.bin\n");
return 0;
}
SrcFile1 = argv[1];
SrcFile2 = argv[2];
DstFile =argv[3];
if(argv[4]==NULL)
offset=OFFSET;
else
offset= strtol(argv[4],NULL,16);
if((soc_file1 = fopen(SrcFile1,"rb")) == NULL){
printf("Can't open %s\n",SrcFile1);
exit(0);
}
if((soc_file2 = fopen(SrcFile2,"rb")) == NULL){
printf("Can't open %s\n",SrcFile2);
exit(0);
}
dest_file = fopen(DstFile,"w+");
if(NULL == dest_file){
printf("Can't open %s\n",DstFile);
exit(0);
}
count = 0;
tmp = fgetc(soc_file1);
while(!feof(soc_file1)){
fputc(tmp,dest_file);
tmp = fgetc(soc_file1);
}
fseek(dest_file, 0, SEEK_END);
currpos = ftell(dest_file);
if(currpos > offset){
printf("the offset is flase\n");
exit(0);
}
while(currpos < offset){
fputc(0,dest_file);
currpos = ftell(dest_file);
}
tmp = fgetc(soc_file2);
while(!feof(soc_file2)){
fputc(tmp,dest_file);
tmp = fgetc(soc_file2);
}
close(dest_file);
close(soc_file1);
close(soc_file2);
}
/*********************END OF FILE**********************************/