zlib_status="disabled"
])
+# Build with bzlib
+AC_ARG_WITH([bzlib],
+ AS_HELP_STRING([--with-bzlib],[Compile with support to decompress bz2 files]),
+ [],[with_bzlib=check])
+AS_IF([test "x$with_bzlib" != "xno" ],
+[
+ AC_CHECK_HEADERS(bzlib.h)
+ AS_IF([test "x$ac_cv_header_bzlib_h" = "xyes"],
+ [
+ AC_CHECK_LIB([bz2],[BZ2_bzReadOpen],
+ [
+ LIBS="-lbz2 ${LIBS}"
+ HAVE_BZLIB_LIB="yes"
+ ],[
+ HAVE_BZLIB_LIB=""
+ ])
+ AS_IF([test "x$HAVE_BZLIB_LIB" != "xyes"],[AC_MSG_ERROR([bzlib was not found])])
+ ],[
+ bzlib_status="not found"
+ ])
+],[
+ bzlib_status="disabled"
+])
+
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_STRUCT_TM
],[test "x$zlib_status" = "xnot found"],[
AC_MSG_NOTICE([zlib.h was not found so it won't be possible to process gzipped files])
])
+
+AS_IF([test "x$bzlib_status" = "xdisabled"],[
+ AC_MSG_NOTICE([Not building with bzlib as requested on the configuration command line])
+],[test "x$bzlib_status" = "xnot found"],[
+ AC_MSG_NOTICE([bzlib.h was not found so it won't be possible to process bzipped files])
+])
BZFILE *BzFile;
//! \c True if end of file is reached.
bool Eof;
- //! Copy of the original file handle.
- int fd;
-}
+ //! Original file in case a rewind is necessary.
+ FILE *File;
+};
/*!
* Read from bzip file.
{
struct BzlibInternalFile *BData=(struct BzlibInternalFile *)Data;
int nread;
+ int bzerr=BZ_OK;
- nread=BZ2_bzread(BData->BzFile,Buffer,Size);
- if (nread==0) BData->Eof=true;
+ if (BData->Eof) return(0);
+ nread=BZ2_bzRead(&bzerr,BData->BzFile,Buffer,Size);
+ if (bzerr==BZ_STREAM_END)
+ BData->Eof=true;
+ else if (bzerr!=BZ_OK)
+ return(0);
return(nread);
}
static void Bzip_Rewind(void *Data)
{
struct BzlibInternalFile *BData=(struct BzlibInternalFile *)Data;
- int fd;
+ int bzerr=BZ_OK;
- BZ2_bzclose(BData->BzFile);
- fd=dup(BData->fd);
- if (fd==-1)
- {
- debuga(__FILE__,__LINE__,_("Cannot rewind bzip file\n"));
- exit(EXIT_FAILURE);
- }
- BData->BzFile=BZ2_bzdopen(fd,"rb");
+ BZ2_bzReadClose(&bzerr,BData->BzFile);
+ rewind(BData->File);
+ BData->BzFile=BZ2_bzReadOpen(&bzerr,BData->File,0,0,NULL,0);
if (!BData->BzFile)
{
debuga(__FILE__,__LINE__,_("Cannot rewind bzip file\n"));
exit(EXIT_FAILURE);
}
+ BData->Eof=false;
}
/*!
static int Bzip_Close(void *Data)
{
struct BzlibInternalFile *BData=(struct BzlibInternalFile *)Data;
+ int bzerr=BZ_OK;
- BZ2_bzclose(BData->BzFile);
- close(BData->fd);
+ BZ2_bzReadClose(&bzerr,BData->BzFile);
+ fclose(BData->File);
free(BData);
return(0);
}
{
FileObject *File;
struct BzlibInternalFile *BData;
+ int bzerr=BZ_OK;
FileObject_SetLastOpenError(NULL);
File=calloc(1,sizeof(*File));
FileObject_SetLastOpenError(_("Not enough memory"));
return(NULL);
}
- BData->fd=dup(fd);
- if (BData->fd==-1)
+ BData->File=fdopen(fd,"rb");
+ if (BData->File==NULL)
{
free(BData);
free(File);
FileObject_SetLastOpenError(_("Error duplicating file descriptor"));
return(NULL);
}
- File=Data=BData;
- BData->BzFile=BZ2_bzdopen(fd,"rb");
+ File->Data=BData;
+ BData->BzFile=BZ2_bzReadOpen(&bzerr,BData->File,0,0,NULL,0);
if (!BData->BzFile)
{
- close(BData->fd);
+ fclose(BData->File);
free(BData);
free(File);
FileObject_SetLastOpenError(_("Error opening bzip file"));
{
int i;
char *newbuf;
- size_t nread;
+ int nread;
if (line==NULL || line->buffer==NULL) return(NULL);
break;
}
nread=(FileObject_Eof(fp_in)!=0) ? 0 : FileObject_Read(fp_in,line->buffer,line->size);
- if (nread==0) return(NULL);
+ if (nread<=0) return(NULL);
line->length=nread;
line->end=0;
}
line->buffer=newbuf;
}
nread=(FileObject_Eof(fp_in)!=0) ? 0 : FileObject_Read(fp_in,line->buffer+line->length,line->size-line->length);
- if (nread==0) {
+ if (nread<=0) {
if (line->end<=line->start) return(NULL);
if (line->end>=line->size) {
line->end=line->size;