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

Function unzReadCurrentFile

DevIL/test/Unzip/unzip.c:996–1117  ·  view source on GitHub ↗

Read bytes from the current file. buf contain buffer where data must be copied len the size of buf. return the number of byte copied if somes bytes are copied return 0 if the end of file was reached return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */

(file, buf, len)

Source from the content-addressed store, hash-verified

994 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
995*/
996extern int ZEXPORT unzReadCurrentFile (file, buf, len)
997 unzFile file;
998 voidp buf;
999 unsigned len;
1000{
1001 int err=UNZ_OK;
1002 uInt iRead = 0;
1003 unz_s* s;
1004 file_in_zip_read_info_s* pfile_in_zip_read_info;
1005 if (file==NULL)
1006 return UNZ_PARAMERROR;
1007 s=(unz_s*)file;
1008 pfile_in_zip_read_info=s->pfile_in_zip_read;
1009
1010 if (pfile_in_zip_read_info==NULL)
1011 return UNZ_PARAMERROR;
1012
1013
1014 if ((pfile_in_zip_read_info->read_buffer == NULL))
1015 return UNZ_END_OF_LIST_OF_FILE;
1016 if (len==0)
1017 return 0;
1018
1019 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1020
1021 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1022
1023 if (len>pfile_in_zip_read_info->rest_read_uncompressed)
1024 pfile_in_zip_read_info->stream.avail_out =
1025 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1026
1027 while (pfile_in_zip_read_info->stream.avail_out>0)
1028 {
1029 if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1030 (pfile_in_zip_read_info->rest_read_compressed>0))
1031 {
1032 uInt uReadThis = UNZ_BUFSIZE;
1033 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1034 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1035 if (uReadThis == 0)
1036 return UNZ_EOF;
1037 if (fseek(pfile_in_zip_read_info->file,
1038 pfile_in_zip_read_info->pos_in_zipfile +
1039 pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
1040 return UNZ_ERRNO;
1041 if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
1042 pfile_in_zip_read_info->file)!=1)
1043 return UNZ_ERRNO;
1044 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1045
1046 pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1047
1048 pfile_in_zip_read_info->stream.next_in =
1049 (Bytef*)pfile_in_zip_read_info->read_buffer;
1050 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1051 }
1052
1053 if (pfile_in_zip_read_info->compression_method==0)

Callers 1

openFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected