test.cpp

来自「tftp client sorser code,Please download 」· C++ 代码 · 共 82 行

CPP
82
字号
#include <stdio.h>#include <ctype.h>#include <sys/types.h>#include <signal.h>#include <fcntl.h>#include <sys/stat.h>#include <errno.h>#include <string.h>#include "gzip.h"int main(int argc, char *argv[]){	char compress_buf[MAX_INBUF];	int compress_len = 0;	int len;	int ret;	int length;	long  n = 0;	long *uncompress_len;	int od;	int flags = O_WRONLY | O_CREAT | O_EXCL | O_BINARY;			memset(compress_buf, 0x00, MAX_INBUF);	ungzipbuf = (char *)malloc(MAX_OUTBUF);		if (argc < 3)	{		printf("argc error\n");		return;	}	ifd = open(argv[1], O_RDONLY | O_BINARY, S_IRWXU);	if (ifd <= 0)	{		perror(ifname);		printf("open file error\n");		return;	}	do 	{		len = read(ifd, compress_buf + compress_len, 1024);		if (len == 0 || len == EOF) 			break;		compress_len += len;	} while (compress_len < INBUFSIZ);	if (compress_len <= 0)	{		printf("read error\n");		return;	}	uncompress_len = &n;	ret = ungzip(compress_buf, compress_len, ungzipbuf, uncompress_len);	if (ret != OK)		return;	n = *uncompress_len;	if (ret != 0)		return;	od = open(argv[2], flags, S_IRUSR);	if (od <= 0)	{		printf("open out file error\n");		return;	}	while ((length = write(od, ungzipbuf, n)) != n)	{		n -= length;		ungzipbuf = ungzipbuf + length;		}	free(ungzipbuf);		close(od);	close(ifd);		return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?