uint32 size() const { assert(fh); uint32 oldPos = gztell(fh); gzseek(fh, 0, SEEK_END); uint32 length = gztell(fh); gzseek(fh, oldPos, SEEK_SET); return length; }
//---------------------------------------------------- int zu_seek(ZUFILE *f, long offset, int whence) { int res = 0; int bzerror=BZ_OK; if (whence == SEEK_END) { return -1; // TODO } switch(f->type) { //SEEK_SET, SEEK_CUR case ZU_COMPRESS_NONE : res = fseek((FILE*)(f->zfile), offset, whence); f->pos = ftell((FILE*)(f->zfile)); break; case ZU_COMPRESS_GZIP : if (whence == SEEK_SET) { res = gzseek((gzFile)(f->zfile), offset, whence); } else { // !!! BUG with SEEK_CUR in ZLIB !!! int p1 = gztell((gzFile)(f->zfile)); res = gzseek((gzFile)(f->zfile), p1+offset, SEEK_SET); } f->pos = gztell((gzFile)(f->zfile)); if (res >= 0) res = 0; break; #ifndef __ANDROID__ case ZU_COMPRESS_BZIP : if (whence==SEEK_SET && offset >= f->pos) { res = zu_bzSeekForward(f, offset-f->pos); } else if (whence==SEEK_CUR) { res = zu_bzSeekForward(f, offset); } else { // BAD : reopen file BZ2_bzReadClose (&bzerror,(BZFILE*)(f->zfile)); bzerror=BZ_OK; rewind(f->faux); f->pos = 0; f->zfile = (void *) BZ2_bzReadOpen(&bzerror,f->faux,0,0,NULL,0); if (bzerror != BZ_OK) { BZ2_bzReadClose (&bzerror,(BZFILE*)(f->zfile)); fclose(f->faux); f->zfile = NULL; f->ok = 0; } res = zu_bzSeekForward(f, offset); } break; #endif } return res; }
long CFile::PImpl::tell() { int ret = -1; int tp = cl_type; if (tp != CLF_TYPE_INVALID) { if (tp == CLF_TYPE_PLAIN) { ret = ftell(cl_plain); } #ifdef USE_ZLIB if (tp == CLF_TYPE_GZIP) { ret = gztell(cl_gz); } #endif // USE_ZLIB #ifdef USE_BZ2LIB if (tp == CLF_TYPE_BZIP2) { // FIXME: need to implement this ret = -1; } #endif // USE_BZ2LIB } else { errno = EBADF; } return ret; }
/* * Auto detects size to distinguish between short and long maq variants * Returns 64 for short * 128 for long * -1 for error */ int maq_detect_size(gzFile fp) { z_off_t curr = gztell(fp); maqmap128_t m; maqmap64_t m64; int i, sz = 128; if (gzread(fp, &m, sizeof(maqmap128_t)) == -1) return -1; gzseek(fp, curr, SEEK_SET); /* We know the sequence size should >= 0 and <= 128 */ if (/*m.size >= 0 &&*/ m.size <= 128) { /* The sequence struct from m.size onwards should be nul padded. */ for (i = m.size; i < 127; i++) { if (m.seq[i] != 0) { sz = 64; break; } } /* Check for valid name */ for (i = 0; i < MAX_NAMELEN; i++) { if (!m.name[i]) break; if (!isprint(m.name[i])) { sz = 64; break; } } } else { sz = 64; } /* If we think the size is now really 64, do a similar check again */ if (sz == 64) { if (gzread(fp, &m64, sizeof(maqmap64_t)) == -1) return -1; gzseek(fp, curr, SEEK_SET); if (/*m64.size < 0 || */ m64.size > 64) return -1; for (i = m64.size; i < 63; i++) { if (m64.seq[i] != 0) return -1; } /* Check for valid name */ for (i = 0; i < MAX_NAMELEN; i++) { if (!m64.name[i]) break; if (!isprint(m64.name[i])) return -1; } } return sz; }
int tarfile_start_txt (struct tarfile * tf, const char * fname) { tf->n = 0; if (tf->type == TARFILE_TAR) { fill_in_header (tf, fname); fgetpos (tf->f, &(tf->record_start)); fwrite (record_header,sizeof(char),512,tf->f); } else if (tf->type == TARFILE_TGZ) { fill_in_header (tf, fname); tf->gz_record_start = gztell (tf->g); gzwrite (tf->g,record_header,512); } else if (tf->type == TARFILE_NOTAR) { char tmp[256]; snprintf(tmp,255,"%s/%s",tf->fname,fname); tf->f=fopen(tmp,"wt"); } else { printf ("Unrecognized tarfile type %d.\n", tf->type); return -1; } return 0; }
int SaveStateGz(gzFile f, long* gzsize) { int Size; unsigned char pMemGpuPic[SZ_GPUPIC]; //if (f == NULL) return -1; gzwrite(f, (void *)PcsxrHeader, sizeof(PcsxrHeader)); gzwrite(f, (void *)&SaveVersion, sizeof(u32)); gzwrite(f, (void *)&Config.HLE, sizeof(boolean)); if (gzsize)GPU_getScreenPic(pMemGpuPic); // Not necessary with ephemeral saves gzwrite(f, pMemGpuPic, SZ_GPUPIC); if (Config.HLE) psxBiosFreeze(1); gzwrite(f, psxM, 0x00200000); gzwrite(f, psxR, 0x00080000); gzwrite(f, psxH, 0x00010000); gzwrite(f, (void *)&psxRegs, sizeof(psxRegs)); // gpu if (!gpufP)gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t)); gpufP->ulFreezeVersion = 1; GPU_freeze(1, gpufP); gzwrite(f, gpufP, sizeof(GPUFreeze_t)); // SPU Plugin cannot change during run, so we query size info just once per session if (!spufP) { spufP = (SPUFreeze_t *)malloc(offsetof(SPUFreeze_t, SPUPorts)); // only first 3 elements (up to Size) SPU_freeze(2, spufP); Size = spufP->Size; SysPrintf("SPUFreezeSize %i/(%i)\n", Size, offsetof(SPUFreeze_t, SPUPorts)); free(spufP); spufP = (SPUFreeze_t *) malloc(Size); spufP->Size = Size; if (spufP->Size <= 0) { gzclose(f); free(spufP); spufP = NULL; return 1; // error } } // spu gzwrite(f, &(spufP->Size), 4); SPU_freeze(1, spufP); gzwrite(f, spufP, spufP->Size); sioFreeze(f, 1); cdrFreeze(f, 1); psxHwFreeze(f, 1); psxRcntFreeze(f, 1); mdecFreeze(f, 1); if(gzsize)*gzsize = gztell(f); gzclose(f); return 0; }
/** Tell position pointer in file. */ int zfpos(file_t *fp) { if(fp->isgzip) { return gztell((voidp)fp->p); } else { return ftell((FILE*)fp->p); } }
/* gztell()/malloc() should be sigblocked ... */ long GZtell(gzFile file){ long off; inGzip++; FL_F_Gzip = "Gztell"; FL_L_Gzip = __LINE__; off = gztell(file); inGzip--; return off; }
/*! */ std::streampos gzfilebuf::seekpos( std::streampos pos, std::ios_base::openmode mode ) { if ( ! is_open() ) { return -1; } std::streampos ret = -1; #ifdef HAVE_LIBZ if ( ( M_impl->open_mode_ & std::ios_base::in ) && ( mode & std::ios_base::in ) ) { ret = gzseek( M_impl->file_, pos, SEEK_SET ); // and reset buffer pointer to initial position M_remained_size = 0; this->setg( M_buf, M_buf, M_buf ); } if ( ( M_impl->open_mode_ & std::ios_base::out ) && ( mode & std::ios_base::out ) ) { std::streampos cur = gztell( M_impl->file_ ); if ( pos <= cur ) { ret = gzseek( M_impl->file_, pos, SEEK_SET ); this->setp( M_buf, M_buf + M_buf_size ); } } #endif return ret; }
static off_t logfile_ftello_gzip(AppContext * const context) { assert(context->logfile_enabled != 0); assert(context->logfile_fd.gzfp != NULL); return (off_t) gztell(context->logfile_fd.gzfp); }
off_t dump_tell( FILE *fp ) { if (gzlevel == -1) { return ftell(fp); } else { return gztell((gzFile)fp); } }
long znztell(znzFile file) { if (file==NULL) { return 0; } #ifdef HAVE_ZLIB if (file->zfptr!=NULL) return (long) gztell(file->zfptr); #endif return ftell(file->nzfptr); }
static unsigned long VFSGZIP_Tell(vfsfile_t *file) { int r; vfsgzipfile_t *vfsgz = (vfsgzipfile_t *)file; r = gztell((gzFile)vfsgz->parent->handle); return r; }
/* Scan one frame of the file to compute the frame size for each point. */ int icp_framesize(gzFile infile, int *rows, int *columns, int *values) { char line[MAX_LINE], token[MAX_LINE]; const char *pline; int ch, ncomma=0, nsemicolon=0, nvalues=0; z_off_t restore_pos; /* Save position */ restore_pos = gztell(infile); /* Get the values line */ if (gzgets(infile, line, sizeof(line)-1) == NULL) return ICP_READ_ERROR; line[sizeof(line)-1] = '\0'; /* Scan the first detector frame */ ch = gzgetc(infile); /* Skip format column character */ if (ch >= 0) ch = gzgetc(infile); /* Peek at first frame character */ if (ch == ' ' || ch == '-' || ch < 0) { /* Empty frame, so return size 0x0 */ *rows = *columns = 0; } else { /* Frame isn't empty so count number of commas and semicolons in frame. */ while (ch >= 0) { ch = gzgetc(infile); if (ch == ',') ncomma++; else if (ch == ';') nsemicolon++; else if (ch == '\r') /* ignored */ ; else if (ch == '\n') { ch = gzgetc(infile); /* Skip format column character */ if (ch >= 0) ch = gzgetc(infile); if (ch==' ' || ch=='-') break; } } /* last row does not end in semicolon so add 1 * last column does not end in comma so add 1 */ *rows = nsemicolon + 1; *columns = (ncomma / *rows) + 1; } /* Count the number of tokens on the line */ //printf("line=%s\n",line); pline = line; while (pline) { pline = scan_token(pline, sizeof(token), token); if (!*token || *token == '\n') break; nvalues++; //printf("values=%s\n",token); } *values = nvalues; /* Restore position */ gzseek(infile, restore_pos, SEEK_SET); return ICP_GOOD; }
unsigned int ZFileTell() { int res = 0; if (TextFile) { res = ftell(FILEHANDLE[ZFileTellHandle]); if (res == -1) fprintf(stderr, "Oups!! gzTell\n"); return(res); } else return gztell(FILEHANDLE[ZFileTellHandle]); }
long ZipFile::tell() const { if (m_gzipFile) { return gztell(m_gzipFile); } else if (m_plainFile) { return ftell(m_plainFile); } else { return 0; } }
value mlgz_gztell(value chan) { gzFile str = Gzfile_val(chan); int res ; res = gztell(str); if(res<0) mlgz_error(str); return Val_unit; }
streampos vcf_file::get_filepos() { if (!compressed) return vcf_in.tellg(); else { return gztell(gzvcf_in); // TODO: Type check } }
/* allowed stream methods */ static int CZ_stream_tell(GB_STREAM *stream, int64_t *npos) { STREAM_COMPRESS *s = (STREAM_COMPRESS *)stream; *npos=gztell (s->handle); if ((*npos)!=-1) return 0; gzclose (s->handle); stream->desc=NULL; return -1; }
static unsigned long VFSGZIP_GetLen(vfsfile_t *file) { int r, currentpos; vfsgzipfile_t *vfsgz = (vfsgzipfile_t *)file; // VFS-FIXME: Error handling currentpos = gztell((gzFile)vfsgz->parent->handle); r = gzseek((gzFile)vfsgz->parent->handle, 0, SEEK_END); gzseek((gzFile)vfsgz->parent->handle, currentpos, SEEK_SET); return r; }
void index_file(char *filename,hashtable sn_index,long start_offset,long length) { gzFile fd1=open_fastq(filename); gzFile fdf=open_fixed_fastq(filename); if (fd1==NULL) { fprintf(stderr,"\nError: Unable to open %s\n",filename); exit(1); } // move to the right position if(length>0) { fprintf(stderr, "\nInternal error: Not implemented\n"); exit(2); } long cline=1; // sn_index creation could be done in parallel while(!gzeof(fd1)) { long long start_pos=gztell(fd1); char *hdr=READ_LINE_HDR(fd1); if ( hdr==NULL) break; int len; //fprintf(stderr,"sn_index: =%s=\n",readname); // get seq //printf("cline=%ld\nLEN=%ld hdr=%s\n",cline,len,hdr); char *seq=READ_LINE_SEQ(fd1); char *hdr2=READ_LINE_HDR2(fd1); char *qual=READ_LINE_QUAL(fd1); char* readname=get_readname(hdr,&len,cline,filename); if (seq==NULL || hdr2==NULL || qual==NULL ) { fprintf(stderr,"\nError in file %s, line %lu: file truncated?\n",filename,cline); exit(1); } if (validate_entry(hdr,hdr2,seq,qual,cline,filename)!=0) { exit(1); } // check for duplicates if ( lookup_header(sn_index,readname)!=NULL ) { fprintf(stderr,"\nError in file %s, line %lu: duplicated sequence %s\n",filename,cline,readname); exit(1); } if ( new_indexentry(sn_index,readname,len,start_pos)==NULL) { fprintf(stderr,"\nError in file %s, line %lu: malloc failed?",filename,cline); exit(1); } replace_dots(start_pos,seq,hdr,hdr2,qual,fdf); PRINT_READS_PROCESSED(cline/4); // cline+=4; } close_fixed_fastq(fdf); gzclose(fd1); return; }
int Reader::tell() { if (m_inRAM) { return m_inRAMCurrentPos; } else if (m_in) { return m_in->tellg(); } #ifdef GTO_SUPPORT_ZIP else { #if ZLIB_VERNUM >= UPDATED_ZLIB_VERNUM return gztell((gzFile_s*)m_gzfile); #else return gztell(m_gzfile); #endif } #else else {
uint64 FCEU_ftell(FCEUFILE *fp) { if(fp->type==1) { return gztell(fp->fp); } else if(fp->type>=2) { return (((MEMWRAP *)(fp->fp))->location); } else return ftell((FILE *)fp->fp); }
int validate_interleaved(char *f) { unsigned long cline=1; unsigned long nreads1=0; gzFile fd1=NULL; fprintf(stderr,"Paired-end interleaved\n"); fd1=open_fastq(f); gzFile fdf=open_fixed_fastq(f); while(!gzeof(fd1)) { long start_pos=gztell(fd1); // Read 1 char *hdr1=READ_LINE_HDR(fd1); if ( hdr1==NULL) break; int len; char *seq1=READ_LINE_SEQ(fd1); char *hdr1_2=READ_LINE_HDR2(fd1); char *qual1=READ_LINE_QUAL(fd1); // Read 2 char *hdr2=READ_LINE_HDR2_1(fd1); char *seq2=READ_LINE_SEQ2(fd1); char *hdr2_2=READ_LINE_HDR2_2(fd1); char *qual2=READ_LINE_QUAL2(fd1); if ( seq1==NULL || hdr1_2==NULL || qual1==NULL || hdr2==NULL || seq2==NULL || hdr2_2==NULL || qual2==NULL ) { fprintf(stderr,"\nError in file %s, line %lu: file truncated?\n",f,cline); return(1); } if (validate_entry(hdr1,hdr1_2,seq1,qual1,cline,f)!=0) { return(1); } if (validate_entry(hdr2,hdr2_2,seq2,qual2,cline+4,f)!=0) { return(1); } char* readname1=get_readname(hdr1,&len,cline,f); char* readname2=get_readname(hdr2,&len,cline+4,f); if ( strcmp(readname1,readname2) ) { fprintf(stderr,"\nError in file %s, line %lu: unpaired read - %s\n",f,cline,readname1); return(1); } PRINT_READS_PROCESSED(cline/4); replace_dots(start_pos,seq1,hdr1,hdr1_2,qual1,fdf); replace_dots(start_pos,seq2,hdr2,hdr2_2,qual2,fdf); // cline+=8; nreads1+=2; } printf("\n"); close_fixed_fastq(fdf); gzclose(fd1); return(nreads1); }
long uproc_io_tell(uproc_io_stream *stream) { switch (stream->type) { case UPROC_IO_GZIP: #if HAVE_ZLIB_H return gztell(stream->s.gz); #endif case UPROC_IO_STDIO: return ftell(stream->s.fp); } uproc_error_msg(UPROC_EINVAL, "invalid stream"); return -1; }
pos_type seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which) { if (file && off == 0 && way == std::ios_base::cur && which == std::ios_base::out) { #if ZLIB_VERNUM >= 0x1240 // gzoffset is only available in zlib 1.2.4 or later return pos_type(gzoffset(file)); #else // return an approximation of file size (only used in progress dialog) z_off_t offset = gztell(file); if (offset > 0) offset /= 4; return pos_type(offset); #endif } return pos_type(off_type(-1)); }
static off_t gzdTell(FDSTACK_t fps) { off_t pos = -1; gzFile gzfile = fps->fp; if (gzfile != NULL) { #if HAVE_GZSEEK pos = gztell(gzfile); if (pos < 0) gzdSetError(fps); #else pos = -2; #endif } return pos; }
long ftell2 (FILE *file) { #undef ftell fmode2_t fmode = get_fmode (file); if (fmode == FM_NORMAL) return ftell (file); else if (fmode == FM_GZIP) return gztell (file); else if (fmode == FM_ZIP) return unztell (file); // returns ftell() of the "current file" else return -1; #define ftell ftell2 }
off_t fzp_tell(struct fzp *fzp) { if(fzp) switch(fzp->type) { case FZP_FILE: return ftello(fzp->fp); case FZP_COMPRESSED: return gztell(fzp->zp); default: unknown_type(fzp->type, __func__); goto error; } not_open(__func__); error: return -1; }
//Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. int GZInputStream::available() { gzseek(m_file, 0, SEEK_END); long max_length = gztell(m_file); gzseek(m_file, 0, SEEK_SET); return max_length; }