/****************INCLUDE********************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
/****************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**********************************/
文件合并c程序
最新推荐文章于 2024-03-27 21:46:12 发布