examples/PIPS/openclibz/src/uncompress.c

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 
00036 #include "OpenCLibzheader.h"
00037 
00038 //
00039 // In case of any error , display the error message .
00040 //
00041 void Error(const char * msg)
00042 {
00043     printf( " %s\n",  msg);
00044     getchar();
00045     getchar();
00046     exit(1);
00047 }
00048 
00049 
00050 
00051 //Compresses the file using libz api's
00052 
00053 void GzUnCompress(gzFile   in, FILE     * out)
00054 
00055 {
00056     static char buf[BUFLEN];
00057     int len;
00058     int err;
00059 
00060     for (;;)
00061     {
00062         len = gzread(in, buf, sizeof(buf)); //libz api to read a compressed file
00063         if (len < 0) Error (gzerror(in, &err));
00064         if (len == 0) break;
00065 
00066         if ((int)fwrite(buf, 1, (unsigned)len, out) != len)
00067         {
00068             Error("failed fwrite");
00069         }
00070     }
00071    if (fclose(out)) Error("failed fclose");
00072 
00073    if (gzclose(in) != Z_OK) // libz api to close a compressed file
00074 
00075    Error("failed gzclose");
00076 
00077 
00078 
00079 }
00080 
00081 
00082 
00083 
00084 //UnCompresses the file using libz api's
00085 
00086 void FileUnCompress( char  * file )
00087 
00088 {
00089     static char buf[MAX_NAME_LEN];
00090     char *infile, *outfile;
00091     FILE  *out;
00092     gzFile in;
00093     char choice[3];
00094     uInt len = (uInt)strlen(file);
00095     strcpy(buf, file);
00096 
00097     if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0)
00098     {
00099         infile = file;
00100         outfile = buf;
00101         outfile[len-3] = '\0'; //create the output filename
00102     }
00103     else
00104     {
00105         outfile = file;
00106         infile = buf;
00107         strcat(infile, GZ_SUFFIX); //create the input filename
00108     }
00109     in = gzopen(infile, "rb"); // libz api to open a compressed file
00110 
00111     if (in == NULL)
00112     {
00113 
00114       Error("file not found ...try again \n");
00115 
00116     }
00117     out = fopen(outfile, "wb"); //open the output filename
00118     if (out == NULL)
00119     {
00120     gzclose(in);       // libz api to close a compressed file
00121     }
00122 
00123     GzUnCompress(in, out);
00124 
00125     printf("do you want to delete the original file (y /n) \n");
00126 
00127     scanf("%s",choice);
00128 
00129     if(choice[0] == 'y')
00130     unlink(file);
00131     printf(" Congrats .... uncompression done ...u can find uncompressed file in the same directory as of the source file\n");
00132 
00133 }
00134 
00135 /*  End of File */

Generated by  doxygen 1.6.2