bzImage文件转gz文件

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值