Exemple #1
0
void g_createBufferFromCompressedFile(const char* sz_file_name, unsigned char** out_p_buffer, unsigned int* out_buffer_length)
{
	if (out_p_buffer)
	{
		*out_p_buffer = NULL;

		zip_file* p_file = zip_fopen(g_p_zip_file, sz_file_name, 0);

		if (p_file)
		{
			unsigned int length = p_file->bytes_left;

			unsigned char* p_buffer = malloc(length);

			if (p_buffer)
			{
				zip_fread(p_file, p_buffer, length);

				*out_p_buffer = p_buffer;

				if (out_buffer_length)
					*out_buffer_length = length;
			}

			zip_fclose(p_file);
		}
	}
}
const bool CCZipFile::open(const char *file)
{
	// Grab the APK (zip) file to access resource
	m_apkArchive = zip_open( CCDeviceFileManager::apkPath.buffer, 0, NULL );
	if( m_apkArchive == NULL )
	{
		DEBUGLOG( "Error loading APK" );
		return false;
	}

    // It's not an image, so add res/raw/ to the path to look in the correct directory
	CCText fullFilePath = "res/raw/";
    fullFilePath += file;

	// Open the supplied file as read-only
	m_File = zip_fopen( m_apkArchive, fullFilePath.buffer, 0 );
	if( m_File != NULL )
	{
		// Get the file size
		struct zip_stat stat;
		zip_stat( m_apkArchive, fullFilePath.buffer, 0, &stat );
		m_Size = stat.size;
		return true;
	}

	DEBUGLOG( "Error loading file %s: %s", fullFilePath.buffer, strerror( errno ) );
    return false;
}
Exemple #3
0
extern void *FileOpen( const char *path, int flags )
{
    data_source     *ds;
    char            *alt_path;

    ds = malloc( sizeof( *ds ) );
    if( ds == NULL )
        return( NULL );

    ds->zf = NULL;
    if( srcType == DS_ZIP ) {
        /* First try opening the file inside a ZIP archive */
        alt_path = flipBackSlashes( path );
        if( alt_path != NULL ) {
            ds->zf = zip_fopen( srcZip, alt_path, 0 );
            ds->type = DS_ZIP;
            free( alt_path );
        }
    }
    if( ds->zf == NULL ) {
        /* If that fails, try opening the file directly */
        ds->fhandle = open( path, flags );
        ds->type = DS_FILE;
    }
    if( ds->type == DS_FILE && ds->fhandle == -1 ) {
        free( ds );
        ds = NULL;
    }
    return( ds );
}
Exemple #4
0
FILE* g_fileOpen(const char* sz_file_name, unsigned int* out_start_offset, unsigned int* out_length)
{
	struct zip_file* p_zip_file = zip_fopen(g_p_zip_file, sz_file_name, 0);

	if (p_zip_file)
	{
		FILE* p_file = NULL;

		if (out_start_offset)
			*out_start_offset = p_zip_file->fpos;

		if (out_length)
			*out_length = p_zip_file->bytes_left;

		zip_fclose(p_zip_file);

		p_file = fopen(g_package_name, "rb");
		fseek(p_file, p_zip_file->fpos, SEEK_SET);

		return p_file;
	}
	else
	{
		return NULL;
	}

}
uint8_t *
zip_read(app_t *app, const char *key, size_t *size)
{
	struct zip_stat stat;
	if(!zip_stat(app->io, key, 0, &stat))
	{
		size_t fsize = stat.size;
		struct zip_file *f = zip_fopen(app->io, key, 0);
		if(f)
		{
			uint8_t *str = malloc(fsize);
			if(str)
			{
				if(zip_fread(f, str, fsize) == -1)
				{
					free(str);
					str = NULL;
					fsize = 0;
				}
				else
				{
					; //success
				}
			}
			zip_fclose(f);

			*size = fsize;
			return str;
		}
	}

	*size = 0;
	return NULL;
}
Exemple #6
0
static int S_archive_file_open(lua_State* L) {
    struct zip** ar        = check_archive(L, 1);
    const char*  path      = (lua_isnumber(L, 2)) ? NULL : luaL_checkstring(L, 2);
    int          path_idx  = (lua_isnumber(L, 2)) ? luaL_checkint(L, 2)-1 : -1;
    int          flags     = (lua_gettop(L) < 3)  ? 0    : luaL_checkint(L, 3);
    struct zip_file** file = (struct zip_file**)
        lua_newuserdata(L, sizeof(struct zip_file*));

    *file = NULL;

    if ( ! *ar ) return 0;

    if ( NULL == path ) {
        *file = zip_fopen_index(*ar, path_idx, flags);
    } else {
        *file = zip_fopen(*ar, path, flags);
    }

    if ( ! *file ) {
        lua_pushnil(L);
        lua_pushstring(L, zip_strerror(*ar));
        return 2;
    }

    luaL_getmetatable(L, ARCHIVE_FILE_MT);
    assert(!lua_isnil(L, -1)/* ARCHIVE_FILE_MT found? */);

    lua_setmetatable(L, -2);

    S_archive_add_ref(L, 1, 1, -1);

    return 1;
}
Exemple #7
0
    void * GetFileData(const utf8 * path, size_t * outSize) const override
    {
        void * data = nullptr;

        size_t index = (size_t)zip_name_locate(_zip, path, 0);
        uint64 dataSize = GetFileSize(index);
        if (dataSize > 0 && dataSize < SIZE_MAX)
        {
            zip_file_t * zipFile = zip_fopen(_zip, path, 0);
            if (zipFile != nullptr)
            {
                data = Memory::Allocate<void>((size_t)dataSize);
                uint64 readBytes = zip_fread(zipFile, data, dataSize);
                if (readBytes != dataSize)
                {
                    Memory::Free(data);
                    data = nullptr;
                    dataSize = 0;
                }
                zip_fclose(zipFile);
            }
        }

        if (outSize != nullptr) *outSize = (size_t)dataSize;
        return data;
    }
Exemple #8
0
static int fzip2buffer(struct zip *fzip, int index, byte **buffer)
{
    struct zip_stat fstat;
    struct zip_file *file = NULL;

    *buffer = NULL;

    zip_stat_index(fzip, index, 0, &fstat);
    *buffer = malloc(fstat.size);

    // Read zipped file
    if((file = zip_fopen(fzip, fstat.name, ZIP_FL_UNCHANGED))==NULL)
        goto error;
    if(zip_fread(file, *buffer, fstat.size)!=fstat.size)
        goto error;
    zip_fclose(file); file = NULL;

    return fstat.size;

error:
    free(*buffer); *buffer = NULL;
    if(file)
        zip_fclose(file);

    return -1;
}
Exemple #9
0
bool ZipFileByteStream::Open(struct zip *archive, const string &path, int flags)
{
    if ( _file != nullptr )
        Close();
    
    _file = zip_fopen(archive, path.c_str(), flags);
    return ( _file != nullptr );
}
ArchiveFile* ZipArchive::OpenFile(const char* name)
{
	zip_file *zip_file = zip_fopen(zip, name, 0);
	if (zip_file == NULL)
		return NULL;

	return new ZipArchiveFile(zip_file);
}
Exemple #11
0
/** @private */
SR_PRIV int sr_sessionfile_check(const char *filename)
{
	struct zip *archive;
	struct zip_file *zf;
	struct zip_stat zs;
	uint64_t version;
	int ret;
	char s[11];

	if (!filename)
		return SR_ERR_ARG;

	if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
		sr_err("Not a regular file: %s.", filename);
		return SR_ERR;
	}

	if (!(archive = zip_open(filename, 0, NULL)))
		/* No logging: this can be used just to check if it's
		 * a sigrok session file or not. */
		return SR_ERR;

	/* check "version" */
	if (!(zf = zip_fopen(archive, "version", 0))) {
		sr_dbg("Not a sigrok session file: no version found.");
		zip_discard(archive);
		return SR_ERR;
	}
	ret = zip_fread(zf, s, sizeof(s) - 1);
	if (ret < 0) {
		sr_err("Failed to read version file: %s",
			zip_file_strerror(zf));
		zip_fclose(zf);
		zip_discard(archive);
		return SR_ERR;
	}
	zip_fclose(zf);
	s[ret] = '\0';
	version = g_ascii_strtoull(s, NULL, 10);
	if (version == 0 || version > 2) {
		sr_dbg("Cannot handle sigrok session file version %" PRIu64 ".",
			version);
		zip_discard(archive);
		return SR_ERR;
	}
	sr_spew("Detected sigrok session file version %" PRIu64 ".", version);

	/* read "metadata" */
	if (zip_stat(archive, "metadata", 0, &zs) < 0) {
		sr_dbg("Not a valid sigrok session file.");
		zip_discard(archive);
		return SR_ERR;
	}
	zip_discard(archive);

	return SR_OK;
}
Exemple #12
0
ResourceManager::file ResourceManager::open(const char *filename) {
#ifdef _DEBUG
	if(fileExists(filename)) {
		FILE *fp = fopen(filename, "rb");
		return file(filename, fp);
	}
#endif
	zip_file *zfile = zip_fopen(archive, filename, 0);
	return file(filename, zfile);
}
Exemple #13
0
char *get_contents_zip(const char *path, const char *name, time_t *last_modified) {

    zip_t *archive = zip_open(path, ZIP_RDONLY, NULL);

    if (archive == NULL) {
        char buffer[1024];
        snprintf(buffer, 1024, "Could not open %s\n", path);
        engine_print(buffer);
        return NULL;
    }

    zip_stat_t stat;
    if (zip_stat(archive, name, 0, &stat) < 0) {
        goto close_archive;
    }

    zip_file_t *f = zip_fopen(archive, name, 0);
    if (f == NULL) {
        print_zip_err("zip_fopen", archive);
        goto close_archive;
    }

    if (last_modified != NULL) {
        *last_modified = stat.mtime;
    }

    char *buf = malloc(stat.size + 1);
    if (!buf) {
        engine_println("zip malloc");
        goto close_f;
    }

    if (zip_fread(f, buf, stat.size) < 0) {
        print_zip_err("zip_fread", archive);
        goto free_buf;
    }
    buf[stat.size] = '\0';

    zip_fclose(f);
    zip_close(archive);

    return buf;

    free_buf:
    free(buf);

    close_f:
    zip_fclose(f);

    close_archive:
    zip_close(archive);

    return NULL;
}
Exemple #14
0
bool ResourceManager::file::rewind() {
#ifdef _DEBUG
	if(ffile) {
		::rewind(ffile);
		return true;
	}
#endif
	if(!zfile)
		return false;
	zip_fclose(zfile);
	zfile = zip_fopen(ResourceManager::instance()->archive, filename.c_str(), 0);
	return true;
}
/** @private */
SR_PRIV int sr_sessionfile_check(const char *filename)
{
	struct stat st;
	struct zip *archive;
	struct zip_file *zf;
	struct zip_stat zs;
	int version, ret;
	char s[11];

	if (!filename)
		return SR_ERR_ARG;

	if (stat(filename, &st) == -1) {
		sr_err("Couldn't stat %s: %s", filename, g_strerror(errno));
		return SR_ERR;
	}

	if (!(archive = zip_open(filename, 0, &ret)))
		/* No logging: this can be used just to check if it's
		 * a sigrok session file or not. */
		return SR_ERR;

	/* check "version" */
	if (!(zf = zip_fopen(archive, "version", 0))) {
		sr_dbg("Not a sigrok session file: no version found.");
		return SR_ERR;
	}
	if ((ret = zip_fread(zf, s, 10)) == -1)
		return SR_ERR;
	zip_fclose(zf);
	s[ret] = 0;
	version = strtoull(s, NULL, 10);
	if (version > 2) {
		sr_dbg("Cannot handle sigrok session file version %d.", version);
		return SR_ERR;
	}
	sr_spew("Detected sigrok session file version %d.", version);

	/* read "metadata" */
	if (zip_stat(archive, "metadata", 0, &zs) == -1) {
		sr_dbg("Not a valid sigrok session file.");
		return SR_ERR;
	}

	if ((ret = zip_close(archive)) == -1) {
		sr_dbg("error closing zipfile: %s", zip_strerror(archive));
		return SR_ERR;
	}

	return SR_OK;
}
Exemple #16
0
static int
do_read(struct zip *z, const char *name, int flags,
	enum when when_ex, int ze_ex, int se_ex)
{
    struct zip_file *zf;
    enum when when_got;
    int err, ze_got, se_got;
    char b[8192];
    zip_int64_t n;
    char expected[80];
    char got[80];

    when_got = WHEN_NEVER;
    ze_got = se_got = 0;
    
    if ((zf=zip_fopen(z, name, flags)) == NULL) {
	when_got = WHEN_OPEN;
	zip_error_get(z, &ze_got, &se_got);
    }
    else {
	while ((n=zip_fread(zf, b, sizeof(b))) > 0)
	    ;
	if (n < 0) {
	    when_got = WHEN_READ;
	    zip_file_error_get(zf, &ze_got, &se_got);
	}
	err = zip_fclose(zf);
	if (when_got == WHEN_NEVER && err != 0) {
	    when_got = WHEN_CLOSE;
	    ze_got = err;
	    se_got = 0;
	}
    }

    if (when_got != when_ex || ze_got != ze_ex || se_got != se_ex) {
	zip_error_to_str(expected, sizeof(expected), ze_ex, se_ex);
	zip_error_to_str(got, sizeof(got), ze_got, se_got);
	printf("%s: %s: got %s error (%s), expected %s error (%s)\n",
	       prg, name,
	       when_name[when_got], got, 
	       when_name[when_ex], expected);
	return 1;
    }
    else if (verbose)
	printf("%s: %s: passed\n", prg, name);

    return 0;
}
Exemple #17
0
struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode) {
	UNUSED(mode);
	// TODO: support truncating, appending and creating, and write
	struct VDirZip* vdz = (struct VDirZip*) vd;

	if ((mode & O_RDWR) == O_RDWR) {
		// libzip doesn't allow for random access, so read/write is impossible without
		// reading the entire file first. This approach will be supported eventually.
		return 0;
	}

	if (mode & O_WRONLY) {
		// Write support is not yet implemented.
		return 0;
	}

	struct zip_stat s;
	if (zip_stat(vdz->z, path, 0, &s) < 0) {
		return 0;
	}

	struct zip_file* zf = zip_fopen(vdz->z, path, 0);
	if (!zf) {
		return 0;
	}

	struct VFileZip* vfz = malloc(sizeof(struct VFileZip));
	vfz->zf = zf;
	vfz->buffer = 0;
	vfz->offset = 0;
	vfz->bufferSize = 0;
	vfz->readSize = 0;
	vfz->fileSize = s.size;

	vfz->d.close = _vfzClose;
	vfz->d.seek = _vfzSeek;
	vfz->d.read = _vfzRead;
	vfz->d.readline = VFileReadline;
	vfz->d.write = _vfzWrite;
	vfz->d.map = _vfzMap;
	vfz->d.unmap = _vfzUnmap;
	vfz->d.truncate = _vfzTruncate;
	vfz->d.size = _vfzSize;
	vfz->d.sync = _vfzSync;

	return &vfz->d;
}
Exemple #18
0
int
main(int argc, char *argv[])
{
    const char *archive;
    struct zip *za;
    struct zip_source *zs;
    char buf[100];
    int err;

    if (argc != 2) {
	fprintf(stderr, "usage: %s archive\n", argv[0]);
	return 1;
    }

    archive = argv[1];
    
    if ((za=zip_open(archive, ZIP_CREATE, &err)) == NULL) {
	zip_error_to_str(buf, sizeof(buf), err, errno);
	fprintf(stderr, "can't open zip archive '%s': %s\n", archive, buf);
	return 1;
    }

    if ((zs=zip_source_buffer(za, teststr, strlen(teststr), 0)) == NULL) {
	fprintf(stderr, "can't create zip_source from buffer: %s\n", zip_strerror(za));
	exit(1);
    }

    if (zip_add(za, file, zs) == -1) {
	zip_source_free(zs);
	fprintf(stderr, "can't add file '%s': %s\n", file, zip_strerror(za));
	return 1;
    }

    if (zip_fopen(za, file, ZIP_FL_UNCHANGED) == NULL) {
	fprintf(stderr, "can't zip_fopen file '%s': %s\n", file, zip_strerror(za));
	return 1;
    }

    if (zip_close(za) == -1) {
	fprintf(stderr, "can't close zip archive '%s': %s\n", archive, zip_strerror(za));
	return 1;
    }

    return 0;
}
Exemple #19
0
static int fs_file_open_in_zip(struct fs_file *f, const char *filename)
{
    struct directory *d;
    char buf[NAME_MAX];

    d = sf_list_tail(&fs.directories);

    get_zip_cwd(buf, NAME_MAX);
    strcat(buf, filename);

    f->isinzip = 1;
    if ((f->zip_file = zip_fopen(d->zip, buf, 0)) == NULL) {
        sf_log(SF_LOG_ERR, "failed to open %s", filename);
        return SF_ERR;
    }

    return SF_OK;
}
Exemple #20
0
uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size) {
	// Figure out the file size first.
	struct zip_stat zstat;
	zip_file *file = zip_fopen(archive, filename, ZIP_FL_NOCASE|ZIP_FL_UNCHANGED);
	if (!file) {
		ELOG("Error opening %s from ZIP", filename);
		return 0;
	}
	zip_stat(archive, filename, ZIP_FL_NOCASE|ZIP_FL_UNCHANGED, &zstat);

	uint8_t *contents = new uint8_t[zstat.size + 1];
	zip_fread(file, contents, zstat.size);
	zip_fclose(file);
	contents[zstat.size] = 0;

	*size = zstat.size;
	return contents;
}
Exemple #21
0
char *get_contents_zip(char *path, char *name, time_t *last_modified) {
	zip_t *archive = zip_open(path, ZIP_RDONLY, NULL);
	if (archive == NULL) {
		print_zip_err("zip_open", archive);
		return NULL;
	}

	zip_stat_t stat;
	if (zip_stat(archive, name, 0, &stat) < 0) {
		print_zip_err("zip_stat", archive);
		goto close_archive;
	}

	zip_file_t *f = zip_fopen(archive, name, 0);
	if (f == NULL) {
		print_zip_err("zip_fopen", archive);
		goto close_archive;
	}

	if (last_modified != NULL) {
		*last_modified = stat.mtime;
	}

	char *buf = malloc(stat.size + 1);
	if (zip_fread(f, buf, stat.size) < 0) {
		print_zip_err("zip_fread", archive);
		goto free_buf;
	}
	buf[stat.size] = '\0';

	zip_fclose(f);
	zip_close(archive);

	return buf;

free_buf:
	free(buf);
	zip_fclose(f);
close_archive:
	zip_close(archive);

	return NULL;
}
Exemple #22
0
QByteArray readZipFile(const char *archiveName, const char *fileName)
{
    int error = 0;
    zip *archive;
    zip_file *file;
    char buffer[1024];
    int readsize = 0;
    QByteArray ret;

    archive = zip_open(archiveName, 0, &error);

    if (!archive)
    {
        qDebug() << "Error when opening archive" << archiveName;
        return ret;
    }

    file = zip_fopen(archive, fileName, 0);

    if (!file)
    {
        qDebug() << "Error when opening file "<< fileName <<" in archive: " << archiveName <<" : " << zip_strerror(archive);
        zip_close(archive);
        return ret;
    }

    do
    {
        ret.append(buffer, readsize);

        readsize = zip_fread(file, buffer, 1024);
    } while (readsize > 0) ;

    if (readsize < 0)
    {
        qDebug() << "Error when reading file "<< fileName <<" in archive: " << archiveName <<" : " << zip_file_strerror(file);
    }

    zip_fclose(file);
    zip_close(archive);

    return ret;
}
Exemple #23
0
bool ZipFileManager::FileExists(const gs2d::str_type::string& fileName) const
{
	if (!IsLoaded())
		return false;

	str_type::string fixedPath = fileName;
	FixSlashesForUnix(fixedPath);

	zip_file *file = zip_fopen(m_archive, fixedPath.c_str(), 0);

	if (file != NULL)
	{
		zip_fclose(file);
		return true;
	}
	else
	{
		return false;
	}
}
Exemple #24
0
wxImage ZipEntry::LoadImage() {
  mutex->Lock();
  if (IsDirectory())
    return wxImage();

  struct zip_stat stat;
  zip_stat(zipFile, innerPath, 0, &stat);

  auto file = zip_fopen(zipFile, innerPath, 0);
  auto size = stat.size;
  auto buffer = new unsigned char[size];
  auto read = zip_fread(file, buffer, size);

  wxMemoryInputStream stream(buffer, size);
  wxImage output(stream);

  delete[] buffer;
  mutex->Unlock();
  return output;
}
Exemple #25
0
//-------------------------------------------------------------------------------------------------------
void Unpack::Decompress(const std::string& from, const std::string& to)
{
	struct zip_stat zs;
	zip_stat(m_pAPKArchive, from.c_str(), ZIP_FL_UNCHANGED , &zs);//读取zip属性
	DEBUGLOG("%s size is %d ", from.c_str(), zs.size);

	byte* data = NEW byte[zs.size];

	zip_file* zipfile;
	zipfile = zip_fopen(m_pAPKArchive, from.c_str(), 0); //打开文件流
	zip_fread(zipfile, data, zs.size); //读取文件

	DEBUGLOG("save to %s", to.c_str());

	FilePtr writeto;
	File::Instance().OpenFile(to.c_str(), File::FILE_WRITE, writeto);
	File::Instance().WriteFile(data, zs.size, 1, writeto);
	File::Instance().CloseFile(writeto);

	zip_fclose(zipfile);//关闭文件
}
Exemple #26
0
/*************************************************
 Function:		readDexFile
 Descroption:
 Input:
	1.zip* z
	2.filename
	3.char* buf
 Output:
 Return:
 Other:
*************************************************/
long readDexFile(struct zip* z, char* filename, unsigned char** buf)
{
    int i;
    long ReadNum = 0;
    struct zip_stat fstat;

    if(z != NULL && NULL != buf)
    {
        zip_stat_init(&fstat);
        int c = zip_get_num_files(z);
        if(c > 0)
        {
            for (i = 0 ; i < c; i++)
            {
                const char* name = zip_get_name(z, i, 0);
                if(0 == strcmp(name,filename))
                {
                    zip_stat(z, name,0,&fstat);
                    //LOGI("File %i:%s Size1: %lld Size2: %lld\n", i,fstat.name,fstat.size ,fstat.comp_size);

                    struct zip_file* file = zip_fopen(z, filename, 0);
                    if (file)
                    {
                        *buf =(unsigned char *)malloc(fstat.size+1);
                        memset(*buf,0,(fstat.size+1));
                        ReadNum = zip_fread(file, *buf,fstat.size);
                        zip_fclose(file);
                    }
                    break;
                }
            }
        }
    }
    else
    {
        return 0;
    }

    return ReadNum;
}
Exemple #27
0
bool ZipFileManager::GetFileBuffer(const str_type::string &fileName, FileBuffer &out)
{
	if (!IsLoaded())
		return false;

	str_type::string fixedPath = fileName;
	FixSlashesForUnix(fixedPath);

	zip_file *file = zip_fopen(m_archive, fixedPath.c_str(), 0);

	if (file == NULL)
		return false;

	struct zip_stat stat;
	zip_stat(m_archive, fixedPath.c_str(), 0, &stat);

	out = FileBuffer(new _FileBuffer<unsigned char>(static_cast<unsigned long>(stat.size)));
	zip_fread(file, out->GetAddress(), stat.size);

	zip_fclose(file);
	return true;
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi,
		void *cb_data)
{
	struct zip_stat zs;
	struct session_vdev *vdev;
	int ret;

	vdev = sdi->priv;

	sr_info("Opening archive %s file %s", vdev->sessionfile,
		vdev->capturefile);

	if (!(vdev->archive = zip_open(vdev->sessionfile, 0, &ret))) {
		sr_err("Failed to open session file '%s': "
		       "zip error %d\n", vdev->sessionfile, ret);
		return SR_ERR;
	}

	if (zip_stat(vdev->archive, vdev->capturefile, 0, &zs) == -1) {
		sr_err("Failed to check capture file '%s' in "
		       "session file '%s'.", vdev->capturefile, vdev->sessionfile);
		return SR_ERR;
	}

	if (!(vdev->capfile = zip_fopen(vdev->archive, vdev->capturefile, 0))) {
		sr_err("Failed to open capture file '%s' in "
		       "session file '%s'.", vdev->capturefile, vdev->sessionfile);
		return SR_ERR;
	}

	/* Send header packet to the session bus. */
    std_session_send_df_header(sdi, LOG_PREFIX);

	/* freewheeling source */
    sr_session_source_add(-1, 0, 0, receive_data, sdi);

	return SR_OK;
}
Exemple #29
0
static jstatus_t __stdcall open(
	struct judgefs *fs,
	/* out */ struct judgefs_file **file,
	const char *path)
{
	struct zipfs *zipfs = (struct zipfs *)fs;
	struct zip_file *zip_file;
	int zep;
	
	EnterCriticalSection(&zipfs->zip_cs);
	zip_file = zip_fopen(zipfs->zip, path, ZIP_FL_NOCASE);
	
	if (zip_file) {
		LeaveCriticalSection(&zipfs->zip_cs);
		*file = (struct judgefs_file *)zip_file;
		judgefs_add_ref(fs);
		return JSTATUS_SUCCESS;
	} else {
		zip_error_get(zipfs->zip, &zep, NULL);
		LeaveCriticalSection(&zipfs->zip_cs);
		return zep_to_jstatus(zep);
	}
}
Exemple #30
-1
AbstractFSProvider::status_t ZIPProvider::ZIPHandle::readFile(const FileName & file, std::vector<uint8_t> & data) {
	if (file.getFile().empty()) {
		return FAILURE;
	}

	const size_t size = fileSize(file);
	if (size == 0) {
		return FAILURE;
	}

	zip_file * fileHandle = zip_fopen(handle, file.getPath().c_str(), 0);
	if (fileHandle == nullptr) {
		WARN(zip_strerror(handle));
		return FAILURE;
	}

	data.resize(size);
	const int bytesRead = zip_fread(fileHandle, data.data(), data.size());
	if (bytesRead == -1) {
		WARN(zip_strerror(handle));
		zip_fclose(fileHandle);
		return FAILURE;
	}
	if (static_cast<size_t>(bytesRead) != size) {
		WARN("Sizes differ during read.");
		zip_fclose(fileHandle);
		return FAILURE;
	}

	if (zip_fclose(fileHandle) == -1) {
		WARN(zip_strerror(handle));
		return FAILURE;
	}

	return OK;
}