?? test.cpp
字號:
#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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -