예제 #1
0
static int
unzip_seek_helper (FILE *file, int offset)
{
  char buffer[MAXBUFSIZE];
  int n, tmp, pos = unztell (file);             // returns ftell() of the "current file"

  if (pos == offset)
    return 0;
  else if (pos > offset)
    {
      unzCloseCurrentFile (file);
      unzip_goto_file (file, unzip_current_file_nr);
      unzOpenCurrentFile (file);
      pos = 0;
    }
  n = offset - pos;
  while (n > 0 && !unzeof (file))
    {
      tmp = unzReadCurrentFile (file, buffer, n > MAXBUFSIZE ? MAXBUFSIZE : n);
      if (tmp < 0)
        return -1;
      n -= tmp;
    }
  return n > 0 ? -1 : 0;
}
예제 #2
0
파일: apklib.c 프로젝트: raimue/apkenv
struct SharedLibrary*
apk_get_shared_libraries(AndroidApk *apk, const char* libdir)
{
    assert(apk != NULL);

    char filename[PATH_MAX];
    FILE *result = NULL;
    char buf[64*1024];
    int read;
    struct SharedLibrary *libs = 0;
    struct SharedLibrary *head = 0;
    int libdirlen = strlen(libdir);

    if (unzGoToFirstFile(apk->zip) != UNZ_OK) {
        return NULL;
    }

    do {
        if (unzGetCurrentFileInfo(apk->zip, NULL, filename, sizeof(filename), NULL, 0, NULL, 0) == UNZ_OK) {
            if (memcmp(filename, libdir, libdirlen) == 0) {
                if (unzOpenCurrentFile(apk->zip) == UNZ_OK) {

#if !defined(PANDORA)
                    strcpy(filename, "/home/user/.apkenv-XXXXXX");
                    int fd = mkstemp(filename);
                    result = fdopen(fd, "w+b");
#else
                    sprintf(filename,"./%s",strdup(filename));
                    recursive_mkdir(filename);
                    result = fopen(filename, "w+b");
#endif
                    while (!unzeof(apk->zip)) {
                        read = unzReadCurrentFile(apk->zip, buf, sizeof(buf));
                        if (read) {
                            assert(fwrite(buf, read, 1, result) == 1);
                        }
                    }
                    fclose(result);
                    unzCloseCurrentFile(apk->zip);
#if defined(PANDORA)
                    sync();
#endif
                    if (libs==0) {
                        libs = malloc(sizeof(struct SharedLibrary));
                        head = libs;
                        libs->next = 0;
                    } else {
                        libs->next = malloc(sizeof(struct SharedLibrary));
                        libs->next->next = 0;
                        libs = libs->next;
                    }
                    libs->filename = strdup(filename);
                }
            }
        }
    } while (unzGoToNextFile(apk->zip) == UNZ_OK);

    return head;
}
예제 #3
0
파일: blocks.c 프로젝트: 1taplay/winbolo
/* Are we EOF */
bool blocksIsEOF() {
  if (logPosition < zipFilePosition) {
    return FALSE;
  }
  if (logFile != NULL) {
    return unzeof(logFile);
  }
  return TRUE;
}
예제 #4
0
nglStreamState nglZipFS::GetState(void* pUnzip) const
{
  if (pUnzip == NULL)
    return eStreamError;

  unzSetCurrentFile(mpPrivate->mZip, pUnzip);
  if (unzeof(mpPrivate->mZip))
    return eStreamEnd;
  
  return eStreamReady;
}
예제 #5
0
int FileAccessZip::get_buffer(uint8_t *p_dst,int p_length) const {

	ERR_FAIL_COND_V(!zfile, -1);
	at_eof = unzeof(zfile);
	if (at_eof)
		return 0;
	int read = unzReadCurrentFile(zfile, p_dst, p_length);
	ERR_FAIL_COND_V(read < 0, read);
	if (read < p_length)
		at_eof = true;
	return read;
};
예제 #6
0
int
feof2 (FILE *file)
{
#undef  feof
  fmode2_t fmode = get_fmode (file);

  if (fmode == FM_NORMAL)
    return feof (file);
  else if (fmode == FM_GZIP)
    return gzeof (file);
  else if (fmode == FM_ZIP)
    return unzeof (file);                       // returns feof() of the "current file"
  else
    return -1;
#define feof    feof2
}
예제 #7
0
파일: apklib.c 프로젝트: raimue/apkenv
enum ApkResult
apk_read_file(AndroidApk *apk, const char *filename, char **buffer, size_t *size)
{
    assert(apk != NULL);

    unz_file_info info;
    int read;
    char *write_pos;
    int remaining;
    int is_zipfile = 0;

    if (unzLocateFile(apk->zip, filename, 2) != UNZ_OK) {
        char *filename2 = malloc(strlen(filename) + strlen(".zip") + 1);
        sprintf(filename2, "%s.zip", filename);
        if (unzLocateFile(apk->zip, filename2, 2) == UNZ_OK) {
            is_zipfile = 1;
        } else {
            return APK_ERROR;
        }
    }

    if (unzGetCurrentFileInfo(apk->zip, &info, NULL, 0,
                NULL, 0, NULL, 0) == UNZ_OK) {
        if (unzOpenCurrentFile(apk->zip) == UNZ_OK) {
            *size = info.uncompressed_size;
            *buffer = malloc(*size);

            write_pos = *buffer;
            remaining = *size;
            while (!unzeof(apk->zip)) {
                read = unzReadCurrentFile(apk->zip, write_pos, remaining);
                write_pos += read;
                remaining -= read;
            }
            unzCloseCurrentFile(apk->zip);

            if (is_zipfile) {
                return apk_uncompress_internal(apk, buffer, size);
            }
            return APK_OK;
        }
    }

    return APK_ERROR;
}
예제 #8
0
static int Eof(ngeVF *f) {
	ngeVFZip* zip = (ngeVFZip*)f;

	return unzeof(zip->file);
}
예제 #9
0
int	File_Unzip_Eof(file_t *file)
{
	return unzeof(file->data);
}
예제 #10
0
파일: zip.cpp 프로젝트: h2so5/PaintField
bool UnzipFile::atEnd() const
{
	return unzeof(d->archive->d->unzip);
}
예제 #11
0
파일: apklib.c 프로젝트: hooddy/apkenv
struct SharedLibrary*
apk_get_shared_libraries(AndroidApk *apk, const char *libdir, const char *datadir)
{
    assert(apk != NULL);

    char filename[PATH_MAX];
    char pathname[PATH_MAX];
    FILE *result = NULL;
    char buf[64*1024];
    int read;
    struct SharedLibrary *libs = 0;
    struct SharedLibrary *head = 0;
    int libdirlen = strlen(libdir);
    char *p;

    if (unzGoToFirstFile(apk->zip) != UNZ_OK) {
        return NULL;
    }

    do {
        if (unzGetCurrentFileInfo(apk->zip, NULL, filename, sizeof(filename), NULL, 0, NULL, 0) == UNZ_OK) {
            if (memcmp(filename, libdir, libdirlen) == 0) {
                if (unzOpenCurrentFile(apk->zip) == UNZ_OK) {

                    snprintf(pathname, sizeof(pathname), "%s%s", datadir, filename);
                    recursive_mkdir(pathname);
                    result = fopen(pathname, "w+b");
                    if (result == NULL) {
                        fprintf(stderr, "can't open %s for writing\n", pathname);
                        unzCloseCurrentFile(apk->zip);
                        break;
                    }
                    while (!unzeof(apk->zip)) {
                        read = unzReadCurrentFile(apk->zip, buf, sizeof(buf));
                        if (read) {
                            assert(fwrite(buf, read, 1, result) == 1);
                        }
                    }
                    fclose(result);
                    unzCloseCurrentFile(apk->zip);

                    if (libs==0) {
                        libs = malloc(sizeof(struct SharedLibrary));
                        head = libs;
                        libs->next = 0;
                    } else {
                        libs->next = malloc(sizeof(struct SharedLibrary));
                        libs->next->next = 0;
                        libs = libs->next;
                    }
                    libs->filename = strdup(pathname);
                    p = strrchr(pathname, '/');
                    *p = 0;
                    libs->dirname = strdup(pathname);
                }
            }
        }
    } while (unzGoToNextFile(apk->zip) == UNZ_OK);

    return head;
}