예제 #1
0
int
vfs_zip_scandir (const char *dir, struct dirent ***namelist, int (*selector) (const struct dirent *), int (*cmp) (const struct dirent **, const struct dirent **)) {
    trace ("vfs_zip_scandir: %s\n", dir);
    int error;
    struct zip *z = zip_open (dir, 0, &error);
    if (!z) {
        trace ("zip_open failed (code: %d)\n", error);
        return -1;
    }

    int num_files = 0;
    const int n = zip_get_num_files(z);
    *namelist = malloc(sizeof(void *) * n);
    for (int i = 0; i < n; i++) {
        const char *nm = zip_get_name(z, i, 0);
        struct dirent entry;
        strncpy(entry.d_name, nm, sizeof(entry.d_name)-1);
        entry.d_name[sizeof(entry.d_name)-1] = '\0';
        if (!selector || selector && selector(&entry)) {
            (*namelist)[num_files] = calloc(1, sizeof(struct dirent));
            strcpy((*namelist)[num_files]->d_name, entry.d_name);
            num_files++;
            trace("vfs_zip: %s\n", nm);
        }
    }

    zip_close (z);
    trace ("vfs_zip: scandir done\n");
    return num_files;
}
예제 #2
0
파일: file.c 프로젝트: abentley/subsurface
int try_to_open_zip(const char *filename)
{
	int success = 0;
	/* Grr. libzip needs to re-open the file, it can't take a buffer */
	struct zip *zip = subsurface_zip_open_readonly(filename, ZIP_CHECKCONS, NULL);

	if (zip) {
		int index;
		for (index = 0;; index++) {
			struct zip_file *file = zip_fopen_index(zip, index, 0);
			if (!file)
				break;
			/* skip parsing the divelogs.de pictures */
			if (strstr(zip_get_name(zip, index, 0), "pictures/"))
				continue;
			zip_read(file, filename);
			zip_fclose(file);
			success++;
		}
		subsurface_zip_close(zip);

		if (!success)
			return report_error(translate("gettextFromC", "No dives in the input file '%s'"), filename);
	}
	return success;
}
예제 #3
0
int main(int argc, char *argv[]){
	int errorp = 0;
	struct zip* zipObj = NULL;
	int num_entries = 0;
	int i;

	if( argc < 2){
		usage();
		return 1;
	}

	zipObj = zip_open(argv[1],0,&errorp);
	if( NULL == zipObj ){
		printf("open zip file failed , error code : %d\n",errorp);
		return 2;
	}

	num_entries = zip_get_num_files(zipObj) ;
	for( i = 0 ; i < num_entries ; ++i ){
		printf("%s\n",zip_get_name(zipObj,i,0) );
	}

	zip_close(zipObj);
	zipObj = NULL ;

	return 0;
};
예제 #4
0
bool zipobject::extractTo(const QString& dirPath){
    int num_entries = zip_get_num_files(m_zip) ;
    for( int i = 0 ; i < num_entries ; ++i ){
        qDebug()<<zip_get_name(m_zip,i,0);
        zip_file* pFile = zip_fopen_index(m_zip,i,0);
        struct zip_stat stat ;
        zip_stat_index(m_zip,i,0,&stat);
        
        const int length = stat.size ;
        char buffer[length +1 ] ;
        int rRead = zip_fread(pFile,buffer,sizeof(buffer));
        if( -1 == rRead ){
            qDebug()<<"read failed : "<<zip_strerror(m_zip);
            return false;
        }
        
        QFileInfo fileInfo(dirPath + '/' + stat.name);
        QDir dir = fileInfo.absoluteDir() ;
        if(!dir.mkpath(".")){
            return false;
        }
        
        QFile file(dirPath + '/' + stat.name);
        file.open(QIODevice::WriteOnly);
        file.write(QByteArray(buffer,length));
        file.close();
    }
    return true;
}
예제 #5
0
파일: jar_file.cpp 프로젝트: Dthird/CBMC
bool get_jar_index(
  const std::string &jar_file,
  std::vector<std::string> &entries)
{
  #ifdef HAVE_LIBZIP
  int zip_error;
  struct zip *zip=zip_open(jar_file.c_str(), 0, &zip_error);

  if(zip==NULL)
    return true;
  
  std::size_t number_of_files=zip_get_num_entries(zip, 0);
  
  for(std::size_t index=0; index<number_of_files; index++)
  {
    std::string file_name=zip_get_name(zip, index, 0);
    entries.push_back(file_name);
  }
  
  zip_close(zip);
  
  return false;
  #else
  return true;
  #endif
}
예제 #6
0
파일: jar_file.cpp 프로젝트: lihaol/cbmc
void jar_filet::open(const std::string &filename)
{
  #ifdef HAVE_LIBZIP
  if(zip!=nullptr)
    zip_close(static_cast<struct zip *>(zip));

  int zip_error;
  zip=zip_open(filename.c_str(), 0, &zip_error);

  if(zip!=nullptr)
  {
    std::size_t number_of_files=
      zip_get_num_entries(static_cast<struct zip *>(zip), 0);

    index.reserve(number_of_files);

    for(std::size_t i=0; i<number_of_files; i++)
    {
      std::string file_name=
        zip_get_name(static_cast<struct zip *>(zip), i, 0);
      index.push_back(file_name);
    }
  }
  #else
  zip=nullptr;
  #endif
}
예제 #7
0
ZIP_EXTERN int
zip_file_rename(struct zip *za, zip_uint64_t idx, const char *name, zip_flags_t flags)
{
    const char *old_name;
    int old_is_dir, new_is_dir;
    
    if (idx >= za->nentry || (name != NULL && strlen(name) > ZIP_UINT16_MAX)) {
	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
	return -1;
    }

    if (ZIP_IS_RDONLY(za)) {
	_zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
	return -1;
    }

    if ((old_name=zip_get_name(za, idx, 0)) == NULL)
	return -1;
								    
    new_is_dir = (name != NULL && name[strlen(name)-1] == '/');
    old_is_dir = (old_name[strlen(old_name)-1] == '/');

    if (new_is_dir != old_is_dir) {
	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
	return -1;
    }

    return _zip_set_name(za, idx, name, flags);
}
예제 #8
0
파일: zipfile.c 프로젝트: laochailan/taisei
static void vfs_zipfile_init_pathmap(VFSNode *node) {
	VFSZipFileData *zdata = node->data1;
	VFSZipFileTLS *tls = vfs_zipfile_get_tls(node, true);
	zip_int64_t num = zip_get_num_entries(tls->zip, 0);

	ht_create(&zdata->pathmap);

	for(zip_int64_t i = 0; i < num; ++i) {
		const char *original = zip_get_name(tls->zip, i, 0);
		char normalized[strlen(original) + 1];

		vfs_path_normalize(original, normalized);

		if(*normalized) {
			char *c = strchr(normalized, 0) - 1;
			if(*c == '/') {
				*c = 0;
			}
		}

		if(strcmp(original, normalized)) {
			ht_set(&zdata->pathmap, normalized, i);
		}
	}
}
예제 #9
0
ZipEntry *ZipEntry::Create(const wxString &path) {
  wxFile file(path);

  int error;
  auto zipFile = zip_fdopen(file.fd(), ZIP_RDONLY, &error);
  file.Detach();
  if (zipFile == nullptr) {
    throw error;
  }
  auto mutex = new wxMutex();
  ZipEntry *root = new ZipEntry(zipFile, mutex, "");

  std::vector<wxString> innerPaths;

  int num_entries = zip_get_num_entries(zipFile, ZIP_FL_UNCHANGED);
  for (int i = 0; i < num_entries; i++) {
    auto path = wxString(zip_get_name(zipFile, i, ZIP_FL_UNCHANGED));
    innerPaths.push_back(path);
  }

  std::sort(innerPaths.begin(), innerPaths.end());
  std::map<wxString, ZipEntry *> entryMap;

  entryMap[""] = root;
  for (auto &path : innerPaths) {
    AddChildrenFromPath(zipFile, mutex, entryMap, path);
  }

  return root;
}
예제 #10
0
파일: zip_util.c 프로젝트: txl0591/RFIDJni
/*************************************************
 Function:		readZipFileName
 Descroption:
 Input:
	1.zip* z
	2.filetype
 Output:
 Return:
 Other:
*************************************************/
int readZipFileName(struct zip* z, char* filetype)
{
    int i;
    struct zip_stat fstat;

    if(z != NULL)
    {
        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(name != NULL)
                {
                    zip_stat(z, name,0,&fstat);
                    //LOGI("File %i:%s Size: %lld Size2: %lld\n", i,fstat.name,fstat.size ,fstat.comp_size);
                }
            }
        }
    }
    else
    {
        return -1;
    }

    return 0;
}
예제 #11
0
void ZipReader::readFileInfo()
{
	zip_int64_t count = zip_get_num_entries(m_archive, 0);
	for (zip_int64_t i = 0; i < count; ++i) {
		QString name = QString::fromUtf8(zip_get_name(m_archive, i, 0));
		m_files.insert(name, i);
	}
}
int
main(int argc, char *argv[])
{
    const char *archive;
    struct zip *za;
    char buf[100];
    int err;
    const char *com;
    int i, len;

    prg = argv[0];

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

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

    if ((com=zip_get_archive_comment(za, &len, 0)) == NULL)
	printf("No archive comment\n");
    else
	printf("Archive comment: %.*s\n", len, com);

    for (i=0; i<zip_get_num_files(za); i++) {
	if ((com=zip_get_file_comment(za, i, &len, 0)) == NULL)
	    printf("No comment for `%s'\n", zip_get_name(za, i, 0));
	else
	    printf("File comment for `%s': %.*s\n", zip_get_name(za, i, 0), len, com);
    }	

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

    return 0;
}
예제 #13
0
파일: zip_read.cpp 프로젝트: PeterTh/native
bool ZipAssetReader::GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter = 0)
{
	ILOG("Zip path: %s", path);
	// We just loop through the whole ZIP file and deduce what files are in this directory, and what subdirectories there are.
	std::set<std::string> files;
	std::set<std::string> directories;
	int numFiles = zip_get_num_files(zip_file_);
	size_t pathlen = strlen(path);
	if (path[pathlen-1] == '/')
		pathlen--;
	for (int i = 0; i < numFiles; i++) {
		const char* name = zip_get_name(zip_file_, i, 0);
		if (!name)
			continue;
		ILOG("Comparing %s %s %i", name, path, pathlen);
		if (!memcmp(name, path, pathlen)) {
			// The prefix is right. Let's see if this is a file or path.
			char *slashPos = strchr(name + pathlen + 1, '/');
			if (slashPos != 0) {
				// A directory.
				std::string dirName = std::string(name + pathlen + 1, slashPos - (name + pathlen + 1));
				directories.insert(dirName);
			} else {
				files.insert(std::string(name + pathlen + 1));
			}
		}
	}

	for (auto diter = directories.begin(); diter != directories.end(); ++diter) {
		FileInfo info;
		info.name = *diter;
		info.fullName = std::string(path);
		if (info.fullName[info.fullName.size()-1] == '/')
			info.fullName = info.fullName.substr(0, info.fullName.size() - 1);
		info.fullName += "/" + *diter;
		info.exists = true;
		info.isWritable = false;
		info.isDirectory = true;
		listing->push_back(info);
	}

	for (auto fiter = files.begin(); fiter != files.end(); ++fiter) {
		FileInfo info;
		info.name = *fiter;
		info.fullName = std::string(path);
		if (info.fullName[info.fullName.size()-1] == '/')
			info.fullName = info.fullName.substr(0, info.fullName.size() - 1);
		info.fullName += "/" + *fiter;
		info.exists = true;
		info.isWritable = false;
		info.isDirectory = false;
		listing->push_back(info);
	}
	
	std::sort(listing->begin(), listing->end());
	return true;
}
예제 #14
0
	COpcPackageReader::COpcPackageReader(_In_ PImportStream pImportStream)
	{
		if (pImportStream.get() == nullptr)
			throw CNMRException(NMR_ERROR_INVALIDPARAM);

		m_ZIPError.str = nullptr;
		m_ZIPError.sys_err = 0;
		m_ZIPError.zip_err = 0;
		m_ZIParchive = nullptr;
		m_ZIPsource = nullptr;

		try {
			// determine stream size
			nfUint64 nStreamSize = pImportStream->retrieveSize();
			pImportStream->seekPosition(0, true);

			if (nStreamSize == 0)
				throw CNMRException(NMR_ERROR_COULDNOTGETSTREAMPOSITION);

			// read ZIP into memory
			m_Buffer.resize ((size_t) nStreamSize);
			pImportStream->readBuffer(&m_Buffer[0], nStreamSize, true);

			// create ZIP objects
			zip_error_init(&m_ZIPError);
			m_ZIPsource = zip_source_buffer_create(&m_Buffer[0], (size_t) nStreamSize, 0, &m_ZIPError);
			if (m_ZIPsource == nullptr)
				throw CNMRException(NMR_ERROR_COULDNOTREADZIPFILE);

			m_ZIParchive = zip_open_from_source(m_ZIPsource, ZIP_RDONLY | ZIP_CHECKCONS, &m_ZIPError);
			if (m_ZIParchive == nullptr)
				throw CNMRException(NMR_ERROR_COULDNOTREADZIPFILE);

			// Get ZIP Content
			nfInt64 nEntryCount = zip_get_num_entries(m_ZIParchive, ZIP_FL_UNCHANGED);
			if (nEntryCount < 0)
				throw CNMRException(NMR_ERROR_COULDNOTREADZIPFILE);

			// List Entries
			nfInt64 nIndex;
			for (nIndex = 0; nIndex < nEntryCount; nIndex++) {
				const char * pszName = zip_get_name(m_ZIParchive, (nfUint64) nIndex, ZIP_FL_ENC_GUESS);
				std::string sUTF8Name(pszName);
				std::wstring sUTF16Name = fnUTF8toUTF16(sUTF8Name);
				m_ZIPEntries.insert(std::make_pair(sUTF16Name, nIndex));
			}

			readContentTypes();
			readRootRelationships();

		}
		catch (...)
		{
			releaseZIP();
			throw;
		}
	}
예제 #15
0
파일: rom.c 프로젝트: k5g/emulika
static int readzippedrom(struct zip *fzip, int index, romspecs *rspecs)
{
    const char *filename;

    filename = zip_get_name(fzip, index, ZIP_FL_UNCHANGED);
    rspecs->romfilename = pathcombc(gettemppath(), filename);
    rspecs->deleterom = 1;

    return fzip2file(fzip, index, rspecs->romfilename);
}
예제 #16
0
void show(zip_t *archive, const char *text)
{
	fprintf(stderr, "--- %s ---\n", text);
	int files_total = zip_get_num_files(archive);
	int i;
	for (i = 0; i<files_total; i++) {
		const char *filename =  zip_get_name(archive, i, 0);
		fprintf(stderr, "file index %d: %s\n", i, filename);
	}
}
static int zip_get_app_directory(struct zip* zf, char** path)
{
	int i = 0;
	int c = zip_get_num_files(zf);
	int len = 0;
	const char* name = NULL;

	/* look through all filenames in the archive */
	do {
		/* get filename at current index */
		name = zip_get_name(zf, i++, 0);
		if (name != NULL) {
			/* check if we have a "Payload/.../" name */
			len = strlen(name);
			if (!strncmp(name, "Payload/", 8) && (len > 8)) {
				/* locate the second directory delimiter */
				const char* p = name + 8;
				do {
					if (*p == '/') {
						break;
					}
				} while(p++ != NULL);

				/* try next entry if not found */
				if (p == NULL)
					continue;

				len = p - name + 1;

				if (*path != NULL) {
					free(*path);
					*path = NULL;
				}

				/* allocate and copy filename */
				*path = (char*)malloc(len + 1);
				strncpy(*path, name, len);

				/* add terminating null character */
				char* t = *path + len;
				*t = '\0';
				break;
			}
		}
	} while(i < c);

	/* check if the path actually exists */
	int zindex = zip_name_locate(zf, *path, 0);
	if (zindex < 0) {
		return -1;
	}

	return 0;
}
예제 #18
0
파일: zipfile.c 프로젝트: laochailan/taisei
const char* vfs_zipfile_iter_shared(VFSNode *node, VFSZipFileData *zdata, VFSZipFileIterData *idata, VFSZipFileTLS *tls) {
	const char *r = NULL;

	for(; !r && idata->idx < idata->num; ++idata->idx) {
		const char *p = zip_get_name(tls->zip, idata->idx, 0);
		const char *p_original = p;

		if(idata->prefix) {
			if(strstartswith(p, idata->prefix)) {
				p += idata->prefix_len;
			} else {
				continue;
			}
		}

		while(!strncmp(p, "./", 2)) {
			// skip the redundant "current directory" prefix
			p += 2;
		}

		if(!strncmp(p, "../", 3)) {
			// sorry, nope. can't work with this
			log_warn("Bad path in zip file: %s", p_original);
			continue;
		}

		if(!*p) {
			continue;
		}

		char *sep = strchr(p, '/');

		if(sep) {
			if(*(sep + 1)) {
				// path is inside a subdirectory, we want only top-level entries
				continue;
			}

			// separator is the last character in the string
			// this is a top-level subdirectory
			// strip the trailing slash

			free(idata->allocated);
			idata->allocated = strdup(p);
			*strchr(idata->allocated, '/') = 0;
			r = idata->allocated;
		} else {
			r = p;
		}
	}

	return r;
}
int
zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st)
{
    const char *name;
    
    if (index < 0 || index >= za->nentry) {
	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
	return -1;
    }

    if ((name=zip_get_name(za, index, flags)) == NULL)
	return -1;
    

    if ((flags & ZIP_FL_UNCHANGED) == 0
	&& ZIP_ENTRY_DATA_CHANGED(za->entry+index)) {
	if (za->entry[index].source->f(za->entry[index].source->ud,
				     st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
	    _zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
	    return -1;
	}
    }
    else {
	if (za->cdir == NULL || index >= za->cdir->nentry) {
	    _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
	    return -1;
	}
	
	st->crc = za->cdir->entry[index].crc;
	st->size = za->cdir->entry[index].uncomp_size;
	st->mtime = za->cdir->entry[index].last_mod;
	st->comp_size = za->cdir->entry[index].comp_size;
	st->comp_method = za->cdir->entry[index].comp_method;
	if (za->cdir->entry[index].bitflags & ZIP_GPBF_ENCRYPTED) {
	    if (za->cdir->entry[index].bitflags & ZIP_GPBF_STRONG_ENCRYPTION) {
		/* XXX */
		st->encryption_method = ZIP_EM_UNKNOWN;
	    }
	    else
		st->encryption_method = ZIP_EM_TRAD_PKWARE;
	}
	else
	    st->encryption_method = ZIP_EM_NONE;
	/* st->bitflags = za->cdir->entry[index].bitflags; */
    }

    st->index = index;
    st->name = name;
    
    return 0;
}
예제 #20
0
ResourceManager::ResourceManager(const char *apkFilename): archive(0) {
	archive = zip_open(apkFilename, 0, NULL);

	if(archive) {
		//Just for debug, print APK contents
		int numFiles = zip_get_num_files(archive);
		for (int i=0; i<numFiles; i++) {
			const char* name = zip_get_name(archive, i, 0);
			if (name == NULL) {
	//			LOGE("Error reading zip file name at index %i : %s", zip_strerror(APKArchive));
				return;
			}
	//		LOGI("File %i : %s\n", i, name);
		}
	}
}
예제 #21
0
파일: lua_zip.c 프로젝트: MarkTseng/lua-zip
static int S_archive_get_name(lua_State* L) {
    struct zip** ar        = check_archive(L, 1);
    int          path_idx  = luaL_checkint(L, 2)-1;
    int          flags     = (lua_gettop(L) < 3)  ? 0    : luaL_checkint(L, 3);
    const char*  name;

    if ( ! *ar ) return 0;

    name = zip_get_name(*ar, path_idx, flags);

    if ( NULL == name ) {
        lua_pushnil(L);
        lua_pushstring(L, zip_strerror(*ar));
        return 2;
    }

    lua_pushstring(L, name);
    return 1;
}
예제 #22
0
void setAPK (const char* apkPath) {
  LOGI("Loading APK %s", apkPath);
  APKArchive = zip_open(apkPath, 0, NULL);
  if (APKArchive == NULL) {
    LOGE("Error loading APK");
    return;
  }

  //Just for debug, print APK contents
  int numFiles = zip_get_num_files(APKArchive);
  for (int i=0; i<numFiles; i++) {
    const char* name = zip_get_name(APKArchive, i, 0);
    if (name == NULL) {
      LOGE("Error reading zip file name at index %i : %s", i, zip_strerror(APKArchive));
      return;
    }
    LOGI("File %i : %s\n", i, name);
  }
}
예제 #23
0
static int fs_cd_file_zip(struct directory *parent, const char *filename)
{
    int isdirexist = 0;
    char buf[NAME_MAX];
    int len;
    zip_int64_t nentries, i;
    struct directory dir;

    if (strcmp(filename, "..") == 0) {
        sf_list_pop(&fs.directories);
        return SF_OK;
    }

    get_zip_cwd(buf, NAME_MAX);
    strcat(buf, filename);
    len = strlen(buf);
    buf[len++] = '/';
    buf[len] = '\0';

    nentries = zip_get_num_entries(parent->zip, 0);
    for (i = 0; i < nentries; ++i) {
        if (strncmp(zip_get_name(parent->zip, i, 0), buf, len) == 0) {
            isdirexist = 1;
            break;
        }
    }

    if (isdirexist) {
        strncpy(dir.name, filename, NAME_MAX);
        dir.iszip = 1;
        dir.isopened = 1;
        dir.zip = parent->zip;
        dir.nopens = parent->nopens + 1;
        sf_list_push(&fs.directories, &dir);
        return SF_OK;
    } else {
        sf_log(SF_LOG_ERR, "not a directory: %s", filename);
        return SF_ERR;
    }
}
예제 #24
0
파일: zip_util.c 프로젝트: txl0591/RFIDJni
/*************************************************
 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;
}
예제 #25
0
static VALUE zipruby_archive_get_name(int argc, VALUE *argv, VALUE self) {
  VALUE index, flags;
  struct zipruby_archive *p_archive;
  int i_flags = 0;
  const char *name;

  rb_scan_args(argc, argv, "11", &index, &flags);
  Check_Type(index, T_FIXNUM);

  if (!NIL_P(flags)) {
    i_flags = NUM2INT(flags);
  }

  Data_Get_Struct(self, struct zipruby_archive, p_archive);
  Check_Archive(p_archive);

  if ((name = zip_get_name(p_archive->archive, NUM2INT(index), i_flags)) == NULL) {
    rb_raise(Error, "Get name failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
  }

  return (name != NULL) ? rb_str_new2(name) : Qnil;
}
예제 #26
0
static int fs_file_walker_zip(struct directory *d,
                              int (*func)(int type, const char *filename,
                                          void *arg),
                              void *arg)
{
    char buf[PATH_MAX];
    size_t len;
    int ret = SF_OK;
    zip_int64_t nentries = zip_get_num_entries(d->zip, 0);
    zip_int64_t i;

    get_zip_cwd(buf, PATH_MAX);
    len = strlen(buf);

    for (i = 0; i < nentries; ++i) {
        const char *filename = zip_get_name(d->zip, i, 0);
        char *ptr;
        if (strncmp(filename, buf, len) == 0) {
            filename += len;
            if (*filename == '\0') {
                continue;
            }
            if ((ptr = strchr(filename, '/')) == NULL) {
                if ((ret = func(FS_FILE, filename, arg)) != SF_OK) {
                    break;
                }
            } else if (ptr == filename + strlen(filename) - 1) {
                char tmp[NAME_MAX];
                strncpy(tmp, filename, strlen(filename) - 1);
                tmp[strlen(filename) - 1] = '\0';
                if ((ret = func(FS_DIR, tmp, arg)) != SF_OK) {
                    break;
                }
            }
        }
    }
    return ret;
}
예제 #27
0
파일: cnpy.cpp 프로젝트: allebacco/cnpy
cnpy::NpArrayDict cnpy::npz_load(const std::string& fname)
{
    Handler<struct zip> zip = zip_open(fname.c_str(), ZIP_CHECKCONS, nullptr);
    if(zip.handle()==nullptr)
        throw std::runtime_error("Error opening npz file "+fname);

    NpArrayDict arrays;
    zip_uint64_t numFiles = zip_get_num_entries(zip.handle(), 0);
    for(zip_uint64_t fid=0; fid<numFiles; ++fid)
    {
        const char* arrName = zip_get_name(zip.handle(), fid, 0);
        if(arrName==nullptr)
            continue;

        Handler<struct zip_file> zipFile = zip_fopen_index(zip.handle(), fid, 0);

        std::string name = arrName;
        name.erase(name.size()-4);
        arrays.insert(NpArrayDictItem(name, load_the_npy_file(zipFile)));
    }

    return arrays;
}
예제 #28
0
static int try_to_open_zip(const char *filename, struct memblock *mem)
{
	int success = 0;
	/* Grr. libzip needs to re-open the file, it can't take a buffer */
	struct zip *zip = subsurface_zip_open_readonly(filename, ZIP_CHECKCONS, NULL);

	if (zip) {
		int index;
		for (index = 0;; index++) {
			struct zip_file *file = zip_fopen_index(zip, index, 0);
			if (!file)
				break;
			/* skip parsing the divelogs.de pictures */
			if (strstr(zip_get_name(zip, index, 0), "pictures/"))
				continue;
			zip_read(file, filename);
			zip_fclose(file);
			success++;
		}
		subsurface_zip_close(zip);
	}
	return success;
}
예제 #29
0
파일: zipfs.c 프로젝트: hiwang123/winjudge
static jstatus_t __stdcall find(
	struct judgefs *fs,
	/* out */ const char **path,
	const char *prefix,
	/* in out */ void **context)
{
	struct zipfs *zipfs = (struct zipfs *)fs;
	uintptr_t *index = (uintptr_t *)context;
	zip_uint64_t num_entries;
	int zep;

	EnterCriticalSection(&zipfs->zip_cs);
	num_entries = zip_get_num_entries(zipfs->zip, ZIP_FL_NOCASE);

	while (1) {
		if (*index < num_entries) {
			const char *name = zip_get_name(zipfs->zip, *index, ZIP_FL_NOCASE);
			if (!name) {
				zip_error_get(zipfs->zip, &zep, NULL);
				LeaveCriticalSection(&zipfs->zip_cs);
				return zep_to_jstatus(zep);
			}
			++*index;
			if (strncmp(name, prefix, strlen(prefix)) == 0) {
				LeaveCriticalSection(&zipfs->zip_cs);
				*path = name;
				return JSTATUS_SUCCESS;
			}
		} else {
			LeaveCriticalSection(&zipfs->zip_cs);
			*path = NULL;
			*index = 0;
			return JSTATUS_SUCCESS;
		}
	}
}
예제 #30
0
파일: zip_rename.c 프로젝트: amogos/tests
ZIP_EXTERN int
zip_rename(struct zip *za, int idx, const char *name)
{
    const char *old_name;
    int old_is_dir, new_is_dir;
    
    if (idx >= za->nentry || idx < 0 || name[0] == '\0') {
	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
	return -1;
    }

    if ((old_name=zip_get_name(za, idx, 0)) == NULL)
	return -1;
								    
    new_is_dir = (name[strlen(name)-1] == '/');
    old_is_dir = (old_name[strlen(old_name)-1] == '/');

    if (new_is_dir != old_is_dir) {
	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
	return -1;
    }

    return _zip_set_name(za, idx, name);
}