struct zip * _zip_open(const char *fn, FILE *fp, int flags, int aflags, int *zep) { struct zip *za; struct zip_cdir *cdir; int i; off_t len; if (fseeko(fp, 0, SEEK_END) < 0) { *zep = ZIP_ER_SEEK; return NULL; } len = ftello(fp); /* treat empty files as empty archives */ if (len == 0) { if ((za=_zip_allocate_new(fn, zep)) == NULL) fclose(fp); else za->zp = fp; return za; } cdir = _zip_find_central_dir(fp, flags, zep, len); if (cdir == NULL) { fclose(fp); return NULL; } if ((za=_zip_allocate_new(fn, zep)) == NULL) { _zip_cdir_free(cdir); fclose(fp); return NULL; } za->cdir = cdir; za->zp = fp; if ((za->entry=(struct zip_entry *)malloc(sizeof(*(za->entry)) * cdir->nentry)) == NULL) { set_error(zep, NULL, ZIP_ER_MEMORY); _zip_free(za); return NULL; } for (i=0; i<cdir->nentry; i++) _zip_entry_new(za); _zip_check_torrentzip(za); za->ch_flags = za->flags; return za; }
struct zip * _zip_open(const char *fn, FILE *fp, unsigned int flags, int *zep) { struct zip *za; struct zip_cdir *cdir; off_t len; if (fseeko(fp, 0, SEEK_END) < 0) { *zep = ZIP_ER_SEEK; return NULL; } len = ftello(fp); /* treat empty files as empty archives */ if (len == 0) { if ((za=_zip_allocate_new(fn, flags, zep)) == NULL) fclose(fp); else za->zp = fp; return za; } cdir = _zip_find_central_dir(fp, flags, zep, len); if (cdir == NULL) { fclose(fp); return NULL; } if ((za=_zip_allocate_new(fn, flags, zep)) == NULL) { _zip_cdir_free(cdir); fclose(fp); return NULL; } za->entry = cdir->entry; za->nentry = cdir->nentry; za->nentry_alloc = cdir->nentry_alloc; za->comment_orig = cdir->comment; za->zp = fp; _zip_check_torrentzip(za, cdir); za->ch_flags = za->flags; free(cdir); return za; }
ZIP_EXTERN struct zip * zip_open(const char *fn, int flags, int *zep) { FILE *fp; struct zip *za; struct zip_cdir *cdir; int i; off_t len; switch (_zip_file_exists(fn, flags, zep)) { case -1: return NULL; case 0: return _zip_allocate_new(fn, zep); default: break; } if ((fp=fopen(fn, "rb")) == NULL) { set_error(zep, NULL, ZIP_ER_OPEN); return NULL; } fseeko(fp, 0, SEEK_END); len = ftello(fp); /* treat empty files as empty archives */ if (len == 0) { if ((za=_zip_allocate_new(fn, zep)) == NULL) fclose(fp); else za->zp = fp; return za; } cdir = _zip_find_central_dir(fp, flags, zep, len); if (cdir == NULL) { fclose(fp); return NULL; } if ((za=_zip_allocate_new(fn, zep)) == NULL) { _zip_cdir_free(cdir); fclose(fp); return NULL; } za->cdir = cdir; za->zp = fp; if ((za->entry=(struct zip_entry *)malloc(sizeof(*(za->entry)) * cdir->nentry)) == NULL) { set_error(zep, NULL, ZIP_ER_MEMORY); _zip_free(za); return NULL; } for (i=0; i<cdir->nentry; i++) _zip_entry_new(za); _zip_check_torrentzip(za); za->ch_flags = za->flags; return za; }
ZIP_EXTERN struct zip * zip_open(const char *fn, int flags, int *zep) { FILE *fp; struct zip *za; struct zip_cdir *cdir; int i; off_t len; switch (_zip_file_exists(fn, flags, zep)) { case -1: return NULL; case 0: return _zip_allocate_new(fn, zep); default: break; } if ((fp=fopen(fn, "rb")) == NULL) { set_error(zep, NULL, ZIP_ER_OPEN); return NULL; } __android_log_print(ANDROID_LOG_VERBOSE, "ZIP", "FILE OPENED"); fseeko(fp, 0, SEEK_END); len = ftello(fp); /* treat empty files as empty archives */ if (len == 0) { if ((za=_zip_allocate_new(fn, zep)) == NULL) fclose(fp); else za->zp = fp; return za; } __android_log_print(ANDROID_LOG_VERBOSE, "ZIP", "SCANNING"); cdir = _zip_find_central_dir(fp, flags, zep, len); if (cdir == NULL) { fclose(fp); return NULL; } __android_log_print(ANDROID_LOG_VERBOSE, "ZIP", "DIR FOUND"); if ((za=_zip_allocate_new(fn, zep)) == NULL) { _zip_cdir_free(cdir); fclose(fp); return NULL; } za->cdir = cdir; za->zp = fp; __android_log_print(ANDROID_LOG_VERBOSE, "ZIP", "ALLOCING ENTRIES"); if ((za->entry=(struct zip_entry *)malloc(sizeof(*(za->entry)) * cdir->nentry)) == NULL) { set_error(zep, NULL, ZIP_ER_MEMORY); _zip_free(za); return NULL; } za->nentry_alloc = cdir->nentry; __android_log_print(ANDROID_LOG_VERBOSE, "ZIP", "FILLING ENTRIES"); for (i=0; i<cdir->nentry; i++) _zip_entry_new2(za); __android_log_print(ANDROID_LOG_VERBOSE, "ZIP", "CHECK TORRENTZIP"); _zip_check_torrentzip(za); za->ch_flags = za->flags; __android_log_print(ANDROID_LOG_VERBOSE, "ZIP", "DONE"); return za; }