Open a Zip file. If the zipfile cannot be opened (file don't exist or in not valid), return NULL. Otherwise, the return value is a unzFile Handle, usable with other unzip functions
| 2922 | // If the zipfile cannot be opened (file don't exist or in not valid), return NULL. |
| 2923 | // Otherwise, the return value is a unzFile Handle, usable with other unzip functions |
| 2924 | unzFile unzOpenInternal(LUFILE *fin) |
| 2925 | { if (fin==NULL) return NULL; |
| 2926 | if (unz_copyright[0]!=' ') {lufclose(fin); return NULL;} |
| 2927 | |
| 2928 | int err=UNZ_OK; |
| 2929 | unz_s us; |
| 2930 | uLong central_pos,uL; |
| 2931 | central_pos = unzlocal_SearchCentralDir(fin); |
| 2932 | if (central_pos==0xFFFFFFFF) err=UNZ_ERRNO; |
| 2933 | if (lufseek(fin,central_pos,SEEK_SET)!=0) err=UNZ_ERRNO; |
| 2934 | // the signature, already checked |
| 2935 | if (unzlocal_getLong(fin,&uL)!=UNZ_OK) err=UNZ_ERRNO; |
| 2936 | // number of this disk |
| 2937 | uLong number_disk; // number of the current dist, used for spanning ZIP, unsupported, always 0 |
| 2938 | if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) err=UNZ_ERRNO; |
| 2939 | // number of the disk with the start of the central directory |
| 2940 | uLong number_disk_with_CD; // number the the disk with central dir, used for spaning ZIP, unsupported, always 0 |
| 2941 | if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) err=UNZ_ERRNO; |
| 2942 | // total number of entries in the central dir on this disk |
| 2943 | if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) err=UNZ_ERRNO; |
| 2944 | // total number of entries in the central dir |
| 2945 | uLong number_entry_CD; // total number of entries in the central dir (same than number_entry on nospan) |
| 2946 | if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) err=UNZ_ERRNO; |
| 2947 | if ((number_entry_CD!=us.gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; |
| 2948 | // size of the central directory |
| 2949 | if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) err=UNZ_ERRNO; |
| 2950 | // offset of start of central directory with respect to the starting disk number |
| 2951 | if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) err=UNZ_ERRNO; |
| 2952 | // zipfile comment length |
| 2953 | if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) err=UNZ_ERRNO; |
| 2954 | if ((central_pos+fin->initial_offset<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; |
| 2955 | if (err!=UNZ_OK) {lufclose(fin);return NULL;} |
| 2956 | |
| 2957 | us.file=fin; |
| 2958 | us.byte_before_the_zipfile = central_pos+fin->initial_offset - (us.offset_central_dir+us.size_central_dir); |
| 2959 | us.central_pos = central_pos; |
| 2960 | us.pfile_in_zip_read = NULL; |
| 2961 | fin->initial_offset = 0; // since the zipfile itself is expected to handle this |
| 2962 | |
| 2963 | unz_s *s = (unz_s*)zmalloc(sizeof(unz_s)); |
| 2964 | *s=us; |
| 2965 | unzGoToFirstFile((unzFile)s); |
| 2966 | return (unzFile)s; |
| 2967 | } |
| 2968 | |
| 2969 | |
| 2970 |
no test coverage detected