MCPcopy Create free account
hub / github.com/DentonW/DevIL / open

Function open

DevIL/test/Unzip/nv_unzip.cpp:26–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24namespace 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 }

Callers

nothing calls this directly

Calls 6

unzOpenFunction · 0.85
unzLocateFileFunction · 0.85
unzGetCurrentFileInfoFunction · 0.85
unzOpenCurrentFileFunction · 0.85
unzReadCurrentFileFunction · 0.85
unzCloseCurrentFileFunction · 0.85

Tested by

no test coverage detected