?? zdecompress.c
字號:
/*
* +-------------------------------------------------------------------+
* | Copyright (c) 1995,2000 TriMedia Technologies Inc. |
* | |
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*/
/*------------------------------ Includes ------------------------------------*/
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <dirent.h>
#include "unistd.h"
#include "errno.h"
#include "tmtypes.h"
#include <tmlib/dprintf.h>
#include "zlib.h"
#ifndef O_BINARY
#define O_BINARY
#endif
/*---------------------------- Test parameters -------------------------------*/
typedef struct stat StatBuf;
/*------------------------ Recursive directory printing ----------------------*/
void print_file_info(String f)
{
StatBuf buf;
Int32 fid_comp, fid_norm;
Int32 lv_read;
Int32 lv_ret;
Byte *comp_mem, *uncomp_mem, *decomp_mem;
UInt32 lv_uncomp_size, lv_decomp_size, lv_comp_size;
if (stat(f,&buf)==0 && S_ISDIR(buf.st_mode)== 0)
{
printf(" * size= %4d dir=%d chr=%d reg=%d ino=%04d | %s\n",
buf.st_size, S_ISDIR(buf.st_mode),
S_ISCHR(buf.st_mode), S_ISREG(buf.st_mode), buf.st_ino, f);
/* save size of uncompressed file */
lv_uncomp_size = buf.st_size;
/* allocate memory for uncompressed and decompressed data */
uncomp_mem = (Byte *)malloc(lv_uncomp_size);
decomp_mem = (Byte *)malloc(lv_uncomp_size);
if (stat(f+2,&buf)!=-1)
printf(" * size= %4d dir=%d chr=%d reg=%d ino=%04d | %s\n",
buf.st_size, S_ISDIR(buf.st_mode),
S_ISCHR(buf.st_mode), S_ISREG(buf.st_mode), buf.st_ino, f+2 );
/* save size of uncompressed file */
lv_comp_size = buf.st_size;
comp_mem = (Byte *)malloc(lv_comp_size);
if(comp_mem == NULL || uncomp_mem == NULL || decomp_mem == NULL)
{
printf("failed to allocate memory\n");
return;
}
/* open uncompressed files */
if((fid_norm = open(f, O_BINARY|O_RDONLY,0)) == -1){
printf("failed to open %s\n",f+2);
close (fid_comp);
return;
}
/* open compressed files */
if((fid_comp = open(f+2, O_BINARY|O_RDONLY,0)) == -1){
printf("failed to open %s\n",f);
return;
}
/* read uncompressed data */
if((lv_read = read(fid_norm,uncomp_mem,lv_uncomp_size)) != lv_uncomp_size){
printf("failed to read data %d %d %s\n",lv_read,lv_uncomp_size,f);
close (fid_norm); close (fid_comp);
return;
}
/* read compressed data */
if((lv_read = read(fid_comp,comp_mem,lv_comp_size)) != lv_comp_size){
printf("failed to read data %d %d %s\n",lv_read,lv_comp_size,f+2);
close (fid_norm); close (fid_comp);
return;
}
/* decompress compressed memory */
if(lv_ret = uncompress(decomp_mem, &lv_decomp_size, comp_mem, lv_comp_size) != Z_OK){
printf("failed uncompress data %d %d %s\n",lv_decomp_size,lv_uncomp_size,f+2);
close (fid_norm); close (fid_comp);
return;
}
/* compare all of the the uncompressed and decompressed data */
if((lv_ret = memcmp(decomp_mem,uncomp_mem,lv_uncomp_size))!= 0){
printf("files have different data %d\n",lv_ret);
close (fid_norm); close (fid_comp);
return;
}
/* experimental compress */
if(lv_ret = compress(comp_mem, &lv_comp_size, uncomp_mem, lv_uncomp_size) != Z_OK){
printf("failed compress data %d %d %s\n",lv_decomp_size,lv_uncomp_size,f);
close (fid_norm); close (fid_comp);
return;
}
free(uncomp_mem);
free(decomp_mem);
free(comp_mem);
close(fid_comp);
close(fid_norm);
}
}
void treewalk(String f)
{
DIR *dirp;
struct dirent *direntp;
dirp = opendir(f);
if (dirp) {
while ( (direntp = readdir( dirp )) != NULL ) {
Char buffer[1000];
sprintf(buffer,"%s/%s",f,direntp->d_name);
print_file_info(buffer);
if (strcmp(direntp->d_name,".") != 0
&& strcmp(direntp->d_name,"..") != 0) {
treewalk(buffer);
}
}
(void)closedir( dirp );
}
}
void dump_uncomp() { treewalk("uncomp"); }
/*------------------------------ Main program --------------------------------*/
Int main()
{
printf("------------- APPLICATION STARTED ------------\n");
dump_uncomp();
printf("-------------SUCCESSFULL TERMINATION ------------\n");
exit (0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -