value mlgz_gzgetc(value chan) { gzFile str=Gzfile_val(chan); int res ; res = gzgetc(Gzfile_val(chan)); if(res<0){ if(gzeof(str)) raise_end_of_file(); else mlgz_error(str); } return Val_int(res); }
int ZIPFAM::SkipRecord(PGLOBAL g, bool header) { // Skip this record if (gzeof(Zfile)) return RC_EF; else if (gzgets(Zfile, To_Buf, Buflen) == Z_NULL) return Zerror(g); if (header) RecordPos(g); return RC_OK; } // end of SkipRecord
static size_t php_gziop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; int read; read = gzread(self->gz_file, buf, count); if (gzeof(self->gz_file)) { stream->eof = 1; } return (read < 0) ? 0 : read; }
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); }
bool auto_detect_fastq(gzFile fp, char * reads_filename) { // autodetect fasta/fastq format bool fastq=false; char c; c = gzgetc(fp); while (c == '#' || c == ';') { // discard this line while (c != -1 && c != '\n') c = gzgetc(fp); if (gzeof(fp)) break; if (c == -1) { fprintf(stderr, "did not find the end of a comment line in the input file [%s]. try disabling input autodetection\n", reads_filename); exit(1); } c = gzgetc(fp); } if (!gzeof(fp)) { if (c == -1) { fprintf(stderr, "did not find a non-comment line in the input file [%s]. try disabling input autodetection\n", reads_filename); exit(1); } if (c == '@') { fprintf(stderr,"detected fastq format in input file [%s]\n", reads_filename); fastq = true; } else if (c == '>') { fprintf(stderr, "detected fasta format in input file [%s]\n", reads_filename); fastq = false; } else { fprintf(stderr, "unrecognized character [%c] in input file [%s]. try disabling input autodetection\n", (char)c, reads_filename); exit(1); } gzungetc(c, fp); } return fastq; }
/* Read the next set of ICP columns from the file */ int icp_readmotors(gzFile infile, int nvector, Real vector[], int *linenum) { char line[MAX_LINE], token[MAX_LINE]; const char *pline; int nvalues = 0; /* Initialize to zeros */ /* TODO: should initialize to NaNs */ memset(vector, 0, sizeof(*vector)*nvector); /* Get the vector line */ if (gzeof(infile)) return ICP_EOF; if (gzgets(infile, line, sizeof(line)-1) == NULL) { #if 1 /* gets failed: can't distinguish read errors from EOF */ return ICP_EOF; #else /* gets failed: are we at the end of the file? */ if (gzeof(infile)) return ICP_EOF; else return ICP_READ_ERROR; #endif } line[sizeof(line)-1]='\0'; (*linenum)++; /* Tokenize and convert to numbers. */ pline = line; while (pline) { pline = scan_token(pline, sizeof(token), token); if (!*token || *token == '\n') break; if (nvalues >= nvector) return ICP_VECTOR_ERROR; vector[nvalues++] = atof(token); // printf("linenum:%d token %d:%s value:%g\n", *linenum, nvalues, token, atof(token)); } if (nvalues < nvector) return ICP_VECTOR_ERROR; return ICP_GOOD; }
u32 GZIPROMReaderSize(void * file) { char useless[1024]; u32 size = 0; /* FIXME this function should first save the current * position and restore it after size calculation */ gzrewind(file); while (gzeof (file) == 0) size += gzread(file, useless, 1024); gzrewind(file); return size; }
int uproc_io_eof(uproc_io_stream *stream) { switch (stream->type) { case UPROC_IO_GZIP: #if HAVE_ZLIB_H return gzeof(stream->s.gz); #endif case UPROC_IO_STDIO: return feof(stream->s.fp); } uproc_error_msg(UPROC_EINVAL, "invalid stream"); return 0; }
int64_t ZipFile::readImpl(char *buffer, int64_t length) { assert(m_gzFile); int64_t nread = gzread(m_gzFile, buffer, length); if (nread == 0 || gzeof(m_gzFile)) { m_eof = true; } else { errno = 0; gzerror(m_gzFile, &errno); if (errno == 1) { // Z_STREAM_END = 1 m_eof = true; } } return (nread < 0) ? 0 : nread; }
static size_t php_gziop_read(php_stream *stream, char *buf, size_t count) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; int read; /* XXX this needs to be looped for the case count > UINT_MAX */ read = gzread(self->gz_file, buf, count); if (gzeof(self->gz_file)) { stream->eof = 1; } return (size_t)((read < 0) ? 0 : read); }
/* Returns the size of a GZ compressed file. */ int gzsize(gzFile *gd) { #define CHUNKSIZE (0x10000) int size = 0, length = 0; unsigned char buffer[CHUNKSIZE]; gzrewind(gd); do { size = gzread(gd, buffer, CHUNKSIZE); if(size <= 0) break; length += size; } while (!gzeof(gd)); gzrewind(gd); return (length); #undef CHUNKSIZE }
static int gz_eof (lua_State *L) { gzFile *zf = tozfile(L); int eof = gzeof (*zf); lua_pushboolean(L, eof); if (eof == 1) { const char* eof_reason; int eof_reason_code; eof_reason = gzerror (*zf, &eof_reason_code); lua_pushboolean (L, eof_reason_code == Z_STREAM_END); lua_pushstring (L, eof_reason); return 3; } return 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 }
VISIBLE int Qeof (QFile *file) { if (file->c != -1) return 0; if (file->sub) return file->pos >= file->size; if (file->file) return feof (file->file); #ifdef HAVE_ZLIB else return gzeof (file->gzfile); #else return -1; #endif }
int zlib_inflate(struct asfd *asfd, const char *source, const char *dest, struct conf *conf) { int ret=-1; size_t b=0; FILE *fp=NULL; gzFile zp=NULL; unsigned char in[ZCHUNK]; if(!(zp=gzopen_file(source, "rb"))) { logw(asfd, conf, "could not open %s in %s\n", source, __func__); goto end; } if(!(fp=open_file(dest, "wb"))) { logw(asfd, conf, "could not open %s in %s: %s\n", dest, __func__, strerror(errno)); goto end; } while((b=gzread(zp, in, ZCHUNK))>0) { if(fwrite(in, 1, b, fp)!=b) { logw(asfd, conf, "error when writing to %s\n", dest); goto end; } } if(!gzeof(zp)) { logw(asfd, conf, "error while gzreading %s in %s\n", source, __func__); goto end; } if(close_fp(&fp)) { logw(asfd, conf, "error when closing %s in %s: %s\n", dest, __func__, strerror(errno)); goto end; } ret=0; end: gzclose_fp(&zp); close_fp(&fp); return ret; }
void read_gzip_unsigned_file(string gzip_file_name, unsigned size, vector<unsigned>& output) { gzFile gzip_file; #ifdef DDEBUG cerr << gzip_file_name << endl; #endif gzip_file = gzopen(gzip_file_name.c_str(), "r"); unsigned i = 0; while (!gzeof(gzip_file) && i < size) { char buffer[256]; gzgets(gzip_file, buffer, 256); output.at(i) = (unsigned)strtol(buffer, NULL, 10); i++; } gzclose(gzip_file); }
int ts_feof(ts_file_t *fp) { TS_TRY(fp); switch(fp->type) { case TS_FILE_STD: return( feof(fp->fp.std)); case TS_FILE_ZLB: return(gzeof(fp->fp.zlb)); case TS_FILE_XZ: return (xzeof(fp->fp.xz)); default: (void)ts_warn(stderr, "\n"); goto fail; } fail: return(0); }
int fzp_eof(struct fzp *fzp) { if(fzp) switch(fzp->type) { case FZP_FILE: return feof(fzp->fp); case FZP_COMPRESSED: return gzeof(fzp->zp); default: unknown_type(fzp->type, __func__); goto error; } not_open(__func__); error: // Non-zero means end of file. Should be OK to use -1 here. return -1; }
static unsigned long int find_kernel_text_from_config(void) { unsigned long int kernel_ram = 0; gzFile f; f = gzopen("/proc/config.gz", "rb"); if (!f) { return 0; } while (!gzeof(f)) { char buffer[1024]; int len; if (gzgets(f, buffer, sizeof (buffer) - 1) == Z_NULL) { break; } buffer[sizeof(buffer) - 1] = '\0'; if (strncmp(buffer, CONFIG_SEARCH_STRING, CONFIG_SEARCH_LENGTH) == 0) { char *p; strtok(buffer + CONFIG_SEARCH_LENGTH, "\r\n"); kernel_ram = strtoul(buffer + CONFIG_SEARCH_LENGTH, &p, 0); if (!*p) { kernel_ram += 0x00008000; printf("Detected kernel physical address at 0x%08x form config\n", kernel_ram); gzclose(f); return kernel_ram; } kernel_ram = 0; break; } } gzclose(f); return kernel_ram; }
ZLibStreamBackend::ZLibStreamBackend(const std::string& file, bool read) { this->file = file; isRead = read; buffer = new MemoryStreamBackend(); if(isRead && isValid()) { gzFile fp = gzopen(file.c_str(), "rb"); while(!gzeof(fp)) { unsigned char b[1024]; long ammount = gzread(fp, b, 1024); buffer->write(b, ammount); } buffer->seekFromStart(0); } }
/********************************************************************************* The Driver must provide this function: static void u_File(char *source,char *target,int level) It is called to decompress a file. The object will pass the following values: source = path of the file to be decompressed target = path of the new decompressed file to create level = compression level You will never receive a erroneus 'level' value *********************************************************************************/ static void u_File(char *source,char *target) { gzFile src; FILE *dst; char buf[GB_Z_BUFFER]; unsigned int len; if ( (src=gzopen(source,"rb"))==NULL) { GB.Error ("Unable to open file for reading"); return; } if ( (dst=fopen(target,"w"))==NULL) { gzclose(src); GB.Error ("Unable to open file for writing"); return; } while (!gzeof(src)) { len=gzread(src,buf,sizeof(char)*GB_Z_BUFFER); if (len==-1) { fclose(dst); gzclose(src); GB.Error("Error while reading data"); return; } if (len) { if (len != fwrite((void*)buf,sizeof(char),len,dst) ) { fclose(dst); gzclose(src); GB.Error("Error while writing data"); return; } } } fclose(dst); gzclose(src); }
bool Babylon::readBlock( bgl_block &block ) { if( gzeof( file ) || file == NULL ) return false; block.length = bgl_readnum( 1 ); block.type = block.length & 0xf; if( block.type == 4 ) return false; // end of file marker block.length >>= 4; block.length = block.length < 4 ? bgl_readnum( block.length + 1 ) : block.length - 4 ; if( block.length ) { block.data = (char *)malloc( block.length ); gzread( file, block.data, block.length ); } return true; }
// Reads an input stream to end-of-file and returns the result as a 'char*' terminated by '\0' // (dynamic allocation in case 'in' is standard input). // char* readFile(gzFile in, int* size_) { char* data = xmalloc<char>(65536); int cap = 65536; int size = 0; while (!gzeof(in)){ if (size == cap){ cap *= 2; data = xrealloc(data, cap); } size += gzread(in, &data[size], 65536); } data = xrealloc(data, size+1); data[size] = '\0'; *size_ = size; return data; }
int main(int argc, char **argv) { int ret; if (argc < 2) { fprintf(stderr, "Usage: %s file.gz\n", argv[0]); return 1; } char * dest_name = NULL; if (argc < 3) { if (strstr(argv[1],".gz") != (argv[1] + strlen(argv[1]) - 3)) { fprintf(stderr, "%s: Not sure if this file is gzipped. Try renaming it to include `.gz' at the end.\n", argv[0]); return 1; } dest_name = strdup(argv[1]); char * t = strstr(dest_name,".gz"); *t = '\0'; } else { dest_name = argv[2]; } gzFile src = gzopen(argv[1], "r"); if (!src) return 1; FILE * dest = fopen(dest_name, "w"); if (!dest) return 1; while (!gzeof(src)) { char buf[1024]; int r = gzread(src, buf, 1024); if (r < 0) return 1; fwrite(buf, r, 1, dest); } fclose(dest); unlink(argv[1]); return 0; }
void ungz(const char * Infile, const char * Outfile){ gzFile r = gzopen(Infile, "rb"); if (!r){ return; } FILE * stream = fopen (Outfile, "wb"); if (!stream){ return; } char buf [4096]; int bytes; do { bytes = gzread(r, &buf, 4096); fwrite(buf, 1, bytes, stream); } while (!gzeof(r)); gzclose_r(r); fclose(stream); }
/*************************************************************** ** countLines: counts lines, returns integer ***************************************************************/ static int gzcountLines(gzFile *file){ int lines = 0; char buffer[1000]; char *token; int fields = 3; while (!gzeof(file)){ gzgets(file, buffer, 1000); token = strtok(buffer, " \t"); if (token == NULL) fields--; token = strtok(NULL, " \t"); if (token == NULL) fields--; token = strtok(NULL, " \t"); if (token == NULL) fields--; if (fields == 3) lines++; } return lines; }
char *XMLwrapper::doloadfile(const char *filename){ char *xmldata=NULL; int filesize=-1; //try get filesize as gzip data (first) gzFile gzfile=gzopen(filename,"rb"); if (gzfile!=NULL){//this is a gzip file // first check it's size int bufsize=1024; char* tmpbuf=new char[bufsize]; filesize=0; while(!gzeof(gzfile)) { filesize+=gzread(gzfile,tmpbuf,bufsize); }; delete []tmpbuf; //rewind the file and load the data xmldata=new char[filesize+1]; ZERO(xmldata,filesize+1); gzrewind(gzfile); gzread(gzfile,xmldata,filesize); gzclose(gzfile); return (xmldata); } else {//this is not a gzip file notgzip: FILE *file=fopen(filename,"rb"); if (file==NULL) return(NULL); fseek(file,0,SEEK_END); filesize=ftell(file); xmldata=new char [filesize+1]; ZERO(xmldata,filesize+1); rewind(file); int tmp=fread(xmldata,filesize,1,file); fclose(file); return(xmldata); }; };
int main(int argc, char* argv[]) { gzFile file; char const* const fileName = argv[1]; if (argc == 1) { fprintf(stderr, "Usage: %s <sequence_file>\n", argv[0]); return 1; } if ((file = gzopen(fileName, "r")) == NULL) { printf("Could not open %s\n", fileName); return 1; } char line[100000]; int k=0; double b=0; double i=0; int fq = 4; /* char *filename = argv[1]; char *word = "fa"; char *ret = strstr(filename, word); if (ret) {fq=1;} */ while (!gzeof(file)) { if ((gzgets(file, line, sizeof(line))) !=NULL) { k++; if (k % fq == 0) { b += strlen(line); i++; } } } gzclose(file); printf("Filename = %s ; Reads = %.0f ; Bases = %.0f\n", argv[1], i, b-i); return 0; }
bool CFileSystem::parseSdp(const std::string& filename, std::list<FileData*>& files) { char c_name[255]; unsigned char c_md5[16]; unsigned char c_crc32[4]; unsigned char c_size[4]; unsigned char length; gzFile in=gzopen(filename.c_str(), "r"); if (in==Z_NULL) { LOG_ERROR("Could not open %s",filename.c_str()); return false; } files.clear(); while (true) { if (!gzread(in, &length, 1)) { if (gzeof(in)) { break; } LOG_ERROR("Unexpected eof in %s", filename.c_str()); gzclose(in); return false; } if (!((gzread(in, &c_name, length)) && (gzread(in, &c_md5, 16)) && (gzread(in, &c_crc32, 4)) && (gzread(in, &c_size, 4)))) { LOG_ERROR("Error reading %s", filename.c_str()); gzclose(in); return false; } FileData* f=new FileData; f->name = std::string(c_name, length); memcpy(f->md5, &c_md5, 16); memcpy(f->crc32, &c_crc32, 4); f->size = parse_int32(c_size); files.push_back(f); } gzclose(in); LOG_DEBUG("Parsed %s with %d files\n", filename.c_str(), (int)files.size()); return true; }
svg_status_t svg_parse_file (svg_t *svg, FILE *file) { svg_status_t status = SVG_STATUS_SUCCESS; gzFile zfile; char buf[SVG_PARSE_BUFFER_SIZE]; int read; zfile = gzdopen (dup(fileno(file)), "r"); if (zfile == NULL) { switch (errno) { case ENOMEM: return SVG_STATUS_NO_MEMORY; case ENOENT: return SVG_STATUS_FILE_NOT_FOUND; default: return SVG_STATUS_IO_ERROR; } } status = svg_parse_chunk_begin (svg); if (status) goto CLEANUP; while (! gzeof (zfile)) { read = gzread (zfile, buf, SVG_PARSE_BUFFER_SIZE); if (read > -1) { status = svg_parse_chunk (svg, buf, read); if (status) goto CLEANUP; } else { status = SVG_STATUS_IO_ERROR; goto CLEANUP; } } status = svg_parse_chunk_end (svg); CLEANUP: gzclose (zfile); return status; }