#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
char c;
char buf[4096];
int len;
char tk[3]={0x1f,0x8b,0x08};
FILE *fip=NULL;
FILE *fop=NULL;
switch(argc)
{
case 1:
printf("Please Input the bzImage file's name:\n");
scanf("%s",buf);
break;
case 2:
strcpy(buf,argv[1]);
break;
default:
printf("argument Error!\n");
return -1;
}
fip=fopen(buf,"rb");
if(!fip)
{
printf("Can not open the input file!\n%s\n",buf);
return -2;
}
strcat(buf,".gz");
fop=fopen(buf,"wb");
if(!fop)
{
printf("Can not create the output file!\n%s\n",buf);
fclose(fip);
return -3;
}
read_again:
if(!fread(&c,sizeof(char),1,fip))goto not_found;
compare_again:
if(c!=tk[0])goto read_again;
if(!fread(&c,sizeof(char),1,fip))goto not_found;
if(c!=tk[1])goto compare_again;
if(!fread(&c,sizeof(char),1,fip))goto not_found;
if(c!=tk[2])goto compare_again;
have_found:
fwrite(tk,sizeof(tk),1,fop);
memset(buf,0x00,sizeof(buf));
while(fread(buf,sizeof(buf),1,fip))
{
fwrite(buf,sizeof(buf),1,fop);
memset(buf,0x00,sizeof(buf));
}
len=sizeof(buf);
while(!buf[--len]);
fwrite(buf,++len,1,fop);
not_found:
fclose(fip);
fclose(fop);
return 0;
}
bzImage文件转gz文件
最新推荐文章于 2022-10-07 17:13:49 发布