- Timestamp:
- 06/03/04 15:57:36 (21 years ago)
- File:
-
- 1 edited
-
ps/trunk/source/lib/res/zip.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/lib/res/zip.cpp
r373 r386 942 942 raw_bytes_read = file_io(&za->f, ofs, raw_size, (void**)0, inf_inflate, zf->read_ctx); 943 943 944 zf->last_raw_ofs = raw_ofs + (off_t)raw_bytes_read; 945 944 946 err = inf_finish_read(zf->read_ctx); 945 947 if(err < 0) … … 1004 1006 return file_unmap(&za->f); 1005 1007 } 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 /* 1019 1020 1021 // note: we go to a bit of trouble to make sure the buffer we allocated 1022 // (if p == 0) is freed when the read fails. 1023 ssize_t zip_read(ZFile* zf, off_t raw_ofs, size_t size, void*& p) 1024 { 1025 CHECK_ZFILE(zf) 1026 1027 ssize_t err = -1; 1028 ssize_t raw_bytes_read; 1029 1030 ZArchive* za = H_USER_DATA(zf->ha, ZArchive); 1031 if(!za) 1032 return ERR_INVALID_HANDLE; 1033 1034 const off_t ofs = zf->ofs + raw_ofs; 1035 1036 // not compressed - just pass it on to file_io 1037 // (avoid the Zip inflate start/finish stuff below) 1038 if(!is_compressed(zf)) 1039 return file_io(&za->f, ofs, size, &p); 1040 // no need to set last_raw_ofs - only checked if compressed. 1041 1042 // compressed 1043 1044 // make sure we continue where we left off 1045 // (compressed data must be read in one stream / sequence) 1046 // 1047 // problem: partial reads 1048 if(raw_ofs != zf->last_raw_ofs) 1049 { 1050 debug_warn("zip_read: compressed read offset is non-continuous"); 1051 return -1; 1052 } 1053 1054 void* our_buf = 0; // buffer we allocated (if necessary) 1055 if(!p) 1056 { 1057 p = our_buf = mem_alloc(size); 1058 if(!p) 1059 return ERR_NO_MEM; 1060 } 1061 1062 err = (ssize_t)inf_start_read(zf->read_ctx, p, size); 1063 if(err < 0) 1064 { 1065 fail: 1066 // we allocated it, so free it now 1067 if(our_buf) 1068 { 1069 mem_free(our_buf); 1070 p = 0; 1071 } 1072 return err; 1073 } 1074 1075 // read blocks from the archive's file starting at ofs and pass them to 1076 // zip_inflate, until all compressed data has been read, or it indicates 1077 // the desired output amount has been reached. 1078 const size_t raw_size = zf->csize; 1079 raw_bytes_read = file_io(&za->f, ofs, raw_size, (void**)0, inf_inflate, zf->read_ctx); 1080 1081 zf->last_raw_ofs = raw_ofs + (off_t)raw_bytes_read; 1082 1083 err = inf_finish_read(zf->read_ctx); 1084 if(err < 0) 1085 goto fail; 1086 1087 err = raw_bytes_read; 1088 1089 // failed - make sure buffer is freed 1090 if(err <= 0) 1091 goto fail; 1092 1093 return err; 1094 } 1095 */
Note:
See TracChangeset
for help on using the changeset viewer.
