Esempio n. 1
0
int detect_filetype(char *file){

	int fileType=0;

	if(is_bz2(file) > 0){
#ifdef HAVE_BZLIB
		fileType = detect_datatype_bz2(file);
#endif
		fileType|= FILE_BZ2;
	}else{
		fileType = detect_datatype(file);
		if(is_gz(file) > 0)
			fileType|= FILE_GZ;
	}

	report_filetype(fileType);

	return fileType;
}
Esempio n. 2
0
void *gzip_load(const char *fname, int *ptr_ulen)
{
    int fd, err;
    gzFile f = 0;
    int ulen = 0;
    void * uncompr = 0;
    off_t len;
    const int omode = O_RDONLY | _O_BINARY;

    fd = open(fname, omode);
    if (fd == -1) {
        //SC68error_add("gzip_load(%s) : %s", fname, strerror(errno));
        goto error;
    }

    len = lseek(fd, 0, SEEK_END);
    if (len == (off_t) -1) {
        //SC68error_add("gzip_load(%s) : %s", fname, strerror(errno));
        goto error;
    }

    if (lseek(fd, 0, SEEK_SET) != 0) {
        //SC68error_add("gzip_load(%s) : %s", fname, strerror(errno));
        goto error;
    }

    ulen = is_gz(fd, len);
    if (ulen == -1) {
        ulen = len;
    }

    f = gzdopen(fd, "rb");
    if (!f) {
        //SC68error_add("gzip_load(%s) :  %s", fname, gzerror(f, &err));
        goto error;
    }
    fd = 0; /* $$$ Closed by gzclose(). Verify fdopen() rules. */

    uncompr = SC68alloc(ulen);
    if (!uncompr) {
        //SC68error_add("gzip_load(%s) : alloc (%d) failed", fname, ulen);
        goto error;
    }
    len = gzread(f, uncompr, ulen);

    if (len != ulen) {
        //SC68error_add("gzip_load(%s) : read : %s",fname, gzerror (f, &err));
        goto error;
    }
    goto end;

error:
    if (uncompr) {
        SC68free(uncompr);
        uncompr = 0;
        ulen = 0;
    }

end:
    if (fd) {
        close(fd);
    }
    if (f) {
        gzclose(f);
    }
    if (ptr_ulen) {
        *ptr_ulen = ulen;
    }

    return uncompr;
}