~ubuntu-branches/ubuntu/hoary/devil/hoary

« back to all changes in this revision

Viewing changes to test/Unzip/nv_unzip.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2005-01-03 19:57:42 UTC
  • Revision ID: james.westby@ubuntu.com-20050103195742-4ipkplcwygu3irv0
Tags: upstream-1.6.7
ImportĀ upstreamĀ versionĀ 1.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************************NVMH1****
 
2
File:
 
3
nv_unzip.cpp
 
4
 
 
5
Copyright (C) 1999, 2000 NVIDIA Corporation
 
6
This file is provided without support, instruction, or implied warranty of any
 
7
kind.  NVIDIA makes no guarantee of its fitness for a particular purpose and is
 
8
not liable under any circumstances for any damages or loss whatsoever arising
 
9
from the use or inability to use this file or items derived from it.
 
10
 
 
11
Comments:
 
12
 
 
13
 
 
14
******************************************************************************/
 
15
 
 
16
#ifndef __nv_util_h__
 
17
#include <nv_util.h>
 
18
#endif // __nv_util_h__
 
19
 
 
20
#ifndef _unz_H
 
21
#include <unzip.h>
 
22
#endif // _unz_H
 
23
 
 
24
namespace unzip
 
25
{
 
26
    unsigned char * open(const char * filename, const char * inzipfile, unsigned int * size)
 
27
    {
 
28
            char filename_inzip[256];
 
29
        int err=UNZ_OK;
 
30
        FILE *fout=NULL;
 
31
        unsigned char * buf;
 
32
        unzFile uf=NULL;
 
33
    
 
34
        uf = unzOpen(filename);
 
35
 
 
36
        if (unzLocateFile(uf,inzipfile,0)!=UNZ_OK) //CASESENSITIVITY
 
37
        {
 
38
            printf("file %s not found in the zipfile\n",filename);
 
39
            return NULL;
 
40
        }
 
41
 
 
42
        unz_file_info file_info;
 
43
            uLong ratio=0;
 
44
            err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
 
45
 
 
46
            if (err!=UNZ_OK)
 
47
            {
 
48
                    printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
 
49
                    return NULL;
 
50
            }
 
51
 
 
52
  
 
53
            err = unzOpenCurrentFile(uf);
 
54
            if (err!=UNZ_OK)
 
55
            {
 
56
                    printf("error %d with zipfile in unzOpenCurrentFile\n",err);
 
57
            return NULL;
 
58
            }
 
59
 
 
60
        *size = file_info.uncompressed_size;
 
61
        buf = new unsigned char[file_info.uncompressed_size];
 
62
 
 
63
        unsigned int count = 0;
 
64
        err = 1;
 
65
        while (err > 0)
 
66
        {
 
67
            err = unzReadCurrentFile(uf,&buf[count],65535);
 
68
                if (err<0)      
 
69
                {
 
70
                        printf("error %d with zipfile in unzReadCurrentFile\n",err);
 
71
                break;
 
72
                }
 
73
            else
 
74
                count += err;
 
75
        }
 
76
        assert(count == file_info.uncompressed_size);
 
77
        if (err==UNZ_OK)
 
78
        {
 
79
                    err = unzCloseCurrentFile (uf);
 
80
                    if (err!=UNZ_OK)
 
81
                    {
 
82
                            printf("error %d with zipfile in unzCloseCurrentFile\n",err);
 
83
                    }
 
84
        }
 
85
        else
 
86
        {
 
87
            *size = 0;
 
88
            delete [] buf;
 
89
            buf = NULL;
 
90
            unzCloseCurrentFile(uf); /* don't lose the error */
 
91
        }
 
92
 
 
93
        return buf;
 
94
    }
 
95
 
 
96
} // namespace unzip
 
 
b'\\ No newline at end of file'