Beispiel #1
0
SDL_RWops *SDL_RWFromZZIP(const char* file, const char* mode)
{
    register SDL_RWops* rwops;
    register ZZIP_FILE* zzip_file;

    if (! strchr (mode, 'r'))
        return SDL_RWFromFile(file, mode);

    zzip_file = zzip_fopen (file, mode);
    if (! zzip_file) return 0;

    rwops = SDL_AllocRW ();
    if (! rwops) {
        errno=ENOMEM;
        zzip_close (zzip_file);
        return 0;
    }

    SDL_RWOPS_ZZIP_DATA(rwops) = zzip_file;
    rwops->read = _zzip_read;
    rwops->write = _zzip_write;
    rwops->seek = _zzip_seek;
    rwops->close = _zzip_close;
    return rwops;
}
Beispiel #2
0
/**
**	CLclose		Library file close
**
**	@param file	CLFile pointer.
*/
global int CLclose(CLFile *file)
{
    int tp, ret = EOF;

    if (file && (tp = file->cl_type) != CLF_TYPE_INVALID) {
	if (tp == CLF_TYPE_PLAIN) {
	    ret = fclose(file->cl_plain);
	}
#ifdef USE_ZLIB
	if (tp == CLF_TYPE_GZIP) {
	    ret = gzclose(file->cl_gz);
	}
#endif	// USE_ZLIB
#ifdef USE_BZ2LIB
	if (tp == CLF_TYPE_BZIP2) {
	    bzclose(file->cl_bz);
	    ret = 0;
	}
#endif	// USE_BZ2LIB
#ifdef USE_ZZIPLIB
	if (tp == CLF_TYPE_ZZIP) {
	    zzip_close(file->cl_zz);
	    ret = 0;
	}
#endif	// USE_ZZIPLIB
	free(file);
    } else {
	errno = EBADF;
    }
    return ret;
}
Beispiel #3
0
// Check for existence of file
bool FileSpecifier::Exists()
{
	// Check whether the file is readable
	err = 0;
	if (access(GetPath(), R_OK) < 0)
		err = errno;
	
#ifdef HAVE_ZZIP
	if (err)
	{
		// Check whether zzip can open the file (slow!)
		ZZIP_FILE* file = zzip_open(unix_path_separators(GetPath()).c_str(), R_OK);
		if (file)
		{
			zzip_close(file);
			return true;
		}
		else
		{
			return false;
		}
	}
#endif
	return (err == 0);
}
	static int _zzip_close(SDL_RWops *context)
	{
	if (! context) return 0; /* may be SDL_RWclose is called by atexit */

	zzip_close (SDL_RWOPS_ZZIP_FILE(context));
	SDL_FreeRW (context);
	return 0;
	}
Beispiel #5
0
/** 关闭ZIP文件流
*/
void FZipFileStream::Close(void)
{
    if( m_pZipFile )
    {
        zzip_close( m_pZipFile );
        m_pZipFile = NULL;
    }
}
Beispiel #6
0
//// read a file contents from either a archive of real directory
void b_zzip_read(task *tsk, pntr *argstack)
{
	char *fileName;
	pntr p = argstack[0];
	int badtype;

	CHECK_ARG(0, CELL_CONS);
	if((badtype = array_to_string(p, &fileName)) >= 0){
		set_error(tsk, "error1: argument is not a string (contains non-char: %s)", cell_types[badtype]);
		return;
	}
	
	ZZIP_FILE* fp = zzip_open (fileName, O_RDONLY|O_BINARY);

    if (! fp){
   		perror (fileName);
    }
    
    int bufSize = 2, blockSize = 1024, numBlocks = 1;
    char buf[bufSize];
    int n, counter = 0;
    char *contents = (char *)calloc(blockSize, sizeof(char));
    
    /* read chunks of bufSize bytes into buf and concatenate them into previous string */
    while( (n = (zzip_read(fp, buf, bufSize-1))) > 0){
    	counter++;
    	
    	if(counter == 1){
//    		strcpy(contents, buf);
			strncat(contents, buf, bufSize-1);
			bufSize = 21;
    	}else{
    		int originalSize = strlen(contents);
    		if( ((blockSize*numBlocks) - (originalSize + 1)) < bufSize){
    			numBlocks++;
    			contents = string_mkroom(contents, blockSize*numBlocks);
    		}

    		strncat(contents, buf, bufSize-1);
//    		printf("%s\n\n\n", contents);
    	}
    	buf[n] = '\0';
    }
    
    argstack[0] = string_to_array(tsk, contents);
	
	zzip_close(fp);
}
Beispiel #7
0
int
ACEXML_ZipCharStream::close (void)
{
  if (this->infile_ != 0)
    {
      zzip_close (this->infile_);
      this->infile_ = 0;
    }
  delete[] this->filename_;
  this->filename_ = 0;
  delete[] this->encoding_;
  this->encoding_ = 0;
  this->size_ = 0;
  this->pos_ = 0;
  this->limit_ = 0;
  return 0;
}
Beispiel #8
0
PSAR_ENTRY *LPP_PsarDecoder_getEntry(const char *filename)
{
    if(!initialized) return NULL;
    zzip_strings_t ext[] = {"", 0};

    ZZIP_FILE *fd = zzip_open_ext_io(filename, O_RDONLY | (0x0), ZZIP_ONLYZIP, ext, &psar_handlers);
    if(fd == NULL)
    {
        #ifdef DEBUG
        dwrite_output("Function %s Line %d : Cannot open the file '%s' for read.\n", __FUNCTION__, __LINE__, filename);
        #endif
        return NULL;
    }

    PSAR_ENTRY *entry = (PSAR_ENTRY*)malloc(sizeof(PSAR_ENTRY));
    if(!entry)
    {
        #ifdef DEBUG
        dwrite_output("Function %s Line %d : Cannot allocate 'entry' to memory.\n", __FUNCTION__, __LINE__);
        #endif
        zzip_close(fd);
        return NULL;
    }

    memset(entry, 0, sizeof(PSAR_ENTRY));

    zzip_seek(fd, 0, SEEK_END);
    entry->len = zzip_tell(fd);
    zzip_rewind(fd);

    if(entry->len <= 0)
    {
        free(entry);
        zzip_fclose(fd);
        #ifdef DEBUG
        dwrite_output("Function %s Line %d : file len is lower than zero.\n", __FUNCTION__, __LINE__);
        #endif
        return NULL;
    }

    entry->data = (u8*)malloc(entry->len);
    zzip_fread(entry->data, 1, entry->len, fd);
    zzip_fclose(fd);

    return(entry);
}
Beispiel #9
0
/**
**	Generate a filename into library.
**
**	Try current directory, user home directory, global directory.
**	This supports .gz, .bz2 and .zip.
**
**	@param file	Filename to open.
**	@param buffer	Allocated buffer for generated filename.
**
**	@return		Pointer to buffer.
*/
global char* LibraryFileName(const char* file,char* buffer)
{
#ifdef USE_ZZIPLIB
    ZZIP_FILE* zp;
#endif
    char* s;

    //
    //	Absolute path or in current directory.
    //
    strcpy(buffer,file);
    if( *buffer=='/' || !access(buffer,R_OK) ) {
	return buffer;
    }
#ifdef USE_ZLIB		// gzip or bzip2 in current directory
    sprintf(buffer,"%s.gz",file);
    if( !access(buffer,R_OK) ) {
	return buffer;
    }
#endif
#ifdef USE_BZ2LIB
    sprintf(buffer,"%s.bz2",file);
    if( !access(buffer,R_OK) ) {
	return buffer;
    }
#endif
#ifdef USE_ZZIPLIB
    strcpy(buffer,file);
    if( (zp=zzip_open(buffer,O_RDONLY|O_BINARY)) ) {
	zzip_close(zp);
	return buffer;
    }
#endif	// USE_ZZIPLIB

    //
    //	Try in map directory
    //
    if( *CurrentMapPath ) {
	DebugLevel3Fn("Map   path: %s\n" _C_ CurrentMapPath);
	if( *CurrentMapPath=='.' || *CurrentMapPath=='/' ) {
	    strcpy(buffer,CurrentMapPath);
	    if( (s=strrchr(buffer,'/')) ) {
		s[1]='\0';
	    }
	    strcat(buffer,file);
	} else {
	    strcpy(buffer,FreeCraftLibPath);
	    if( *buffer ) {
		strcat(buffer,"/");
	    }
	    strcat(buffer,CurrentMapPath);
	    if( (s=strrchr(buffer,'/')) ) {
		s[1]='\0';
	    }
	    strcat(buffer,file);
	}
	if( !access(buffer,R_OK) ) {
	    return buffer;
	}

#ifdef USE_ZLIB		// gzip or bzip2 in map directory directory
	strcat(buffer,".gz");
	if( !access(buffer,R_OK) ) {
	    return buffer;
	}
	*strrchr(buffer,'.')='\0';
#endif
#ifdef USE_BZ2LIB
	strcat(buffer,".bz2");
	if( !access(buffer,R_OK) ) {
	    return buffer;
	}
	*strrchr(buffer,'.')='\0';
#endif
#ifdef USE_ZZIPLIB
	if( (zp=zzip_open(buffer,O_RDONLY|O_BINARY)) ) {
	    zzip_close(zp);
	    return buffer;
	}
#endif	// USE_ZZIPLIB
    }

    if( (s = getenv("HOME")) ) {
	//
	//	In user home directory
	//
	sprintf(buffer,"%s/%s/%s",s,FREECRAFT_HOME_PATH,file);
	if( !access(buffer,R_OK) ) {
	    return buffer;
	}
#ifdef USE_ZLIB		// gzip or bzip2 in user home directory
	sprintf(buffer,"%s/%s/%s.gz",s,FREECRAFT_HOME_PATH,file);
	if( !access(buffer,R_OK) ) {
	    return buffer;
	}
#endif
#ifdef USE_BZ2LIB
	sprintf(buffer,"%s/%s/%s.bz2",s,FREECRAFT_HOME_PATH,file);
	if( !access(buffer,R_OK) ) {
	    return buffer;
	}
#endif
#ifdef USE_ZZIPLIB
	sprintf(buffer,"%s/%s/%s",s,FREECRAFT_HOME_PATH,file);
	if( (zp=zzip_open(buffer,O_RDONLY|O_BINARY)) ) {
	    zzip_close(zp);
	    return buffer;
	}
#endif	// USE_ZZIPLIB
    }

    //
    //	In global shared directory
    //
    sprintf(buffer,"%s/%s",FreeCraftLibPath,file);
    if( !access(buffer,R_OK) ) {
	return buffer;
    }
#ifdef USE_ZLIB		// gzip or bzip2 in global shared directory
    sprintf(buffer,"%s/%s.gz",FreeCraftLibPath,file);
    if( !access(buffer,R_OK) ) {
	return buffer;
    }
#endif
#ifdef USE_BZ2LIB
    sprintf(buffer,"%s/%s.bz2",FreeCraftLibPath,file);
    if( !access(buffer,R_OK) ) {
	return buffer;
    }
#endif
#ifdef USE_ZZIPLIB
    sprintf(buffer,"%s/%s",FreeCraftLibPath,file);
    if( (zp=zzip_open(buffer,O_RDONLY|O_BINARY)) ) {
	zzip_close(zp);
	return buffer;
    }
#endif	// USE_ZZIPLIB
    DebugLevel0Fn("File `%s' not found\n" _C_ file);

    strcpy(buffer,file);
    return buffer;
}
Beispiel #10
0
void ZIPROMReaderDeInit(void * file)
{
	zzip_close((ZZIP_FILE*)file);
}