]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
try to avoid direct usage of .Fd() if possible and do read()s and co
[apt.git] / apt-pkg / contrib / fileutl.cc
index 58cd6dceb3637bccde9958156a40900b11b53fce..bb836e93be46e602c0e93c94a0ac19ffe1e4de51 100644 (file)
 #include <set>
 #include <algorithm>
 
+// FIXME: Compressor Fds have some speed disadvantages and are a bit buggy currently,
+// so while the current implementation satisfies the testcases it is not a real option
+// to disable it for now
+#define APT_USE_ZLIB 1
+#if APT_USE_ZLIB
 #include <zlib.h>
+#else
+#pragma message "Usage of zlib is DISABLED!"
+#endif
 
 #ifdef WORDS_BIGENDIAN
 #include <inttypes.h>
@@ -57,8 +65,19 @@ using namespace std;
 
 class FileFdPrivate {
        public:
+#if APT_USE_ZLIB
        gzFile gz;
-       FileFdPrivate() : gz(NULL) {};
+#else
+       void* gz;
+#endif
+       int compressed_fd;
+       pid_t compressor_pid;
+       bool pipe;
+       APT::Configuration::Compressor compressor;
+       unsigned int openmode;
+       unsigned long long seekpos;
+       FileFdPrivate() : gz(NULL), compressed_fd(-1), compressor_pid(-1), pipe(false),
+                         openmode(0), seekpos(0) {};
 };
 
 // RunScripts - Run a set of scripts from a configuration subtree      /*{{{*/
@@ -727,95 +746,90 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
 // FileFd::Open - Open a file                                          /*{{{*/
 // ---------------------------------------------------------------------
 /* The most commonly used open mode combinations are given with Mode */
-bool FileFd::Open(string FileName,OpenMode Mode,CompressMode Compress, unsigned long const Perms)
+bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress, unsigned long const Perms)
 {
    if (Mode == ReadOnlyGzip)
       return Open(FileName, ReadOnly, Gzip, Perms);
-   Close();
-   d = new FileFdPrivate;
-   Flags = AutoClose;
 
    if (Compress == Auto && (Mode & WriteOnly) == WriteOnly)
       return _error->Error("Autodetection on %s only works in ReadOnly openmode!", FileName.c_str());
-   if ((Mode & WriteOnly) != WriteOnly && (Mode & (Atomic | Create | Empty | Exclusive)) != 0)
-      return _error->Error("ReadOnly mode for %s doesn't accept additional flags!", FileName.c_str());
-
-   int fileflags = 0;
-#define if_FLAGGED_SET(FLAG, MODE) if ((Mode & FLAG) == FLAG) fileflags |= MODE
-   if_FLAGGED_SET(ReadWrite, O_RDWR);
-   else if_FLAGGED_SET(ReadOnly, O_RDONLY);
-   else if_FLAGGED_SET(WriteOnly, O_WRONLY);
-   else return _error->Error("No openmode provided in FileFd::Open for %s", FileName.c_str());
-
-   if_FLAGGED_SET(Create, O_CREAT);
-   if_FLAGGED_SET(Exclusive, O_EXCL);
-   else if_FLAGGED_SET(Atomic, O_EXCL);
-   if_FLAGGED_SET(Empty, O_TRUNC);
-#undef if_FLAGGED_SET
 
    // FIXME: Denote inbuilt compressors somehow - as we don't need to have the binaries for them
    std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
    std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin();
    if (Compress == Auto)
    {
-      Compress = None;
       for (; compressor != compressors.end(); ++compressor)
       {
         std::string file = std::string(FileName).append(compressor->Extension);
         if (FileExists(file) == false)
            continue;
         FileName = file;
-        if (compressor->Binary == ".")
-           Compress = None;
-        else
-           Compress = Extension;
         break;
       }
    }
    else if (Compress == Extension)
    {
-      Compress = None;
-      std::string ext = flExtension(FileName);
-      if (ext != FileName)
+      std::string::size_type const found = FileName.find_last_of('.');
+      std::string ext;
+      if (found != std::string::npos)
       {
-        ext = "." + ext;
-        for (; compressor != compressors.end(); ++compressor)
-           if (ext == compressor->Extension)
-              break;
+        ext = FileName.substr(found);
+        if (ext == ".new" || ext == ".bak")
+        {
+           std::string::size_type const found2 = FileName.find_last_of('.', found - 1);
+           if (found2 != std::string::npos)
+              ext = FileName.substr(found2, found - found2);
+           else
+              ext.clear();
+        }
       }
+      for (; compressor != compressors.end(); ++compressor)
+        if (ext == compressor->Extension)
+           break;
+      // no matching extension - assume uncompressed (imagine files like 'example.org_Packages')
+      if (compressor == compressors.end())
+        for (compressor = compressors.begin(); compressor != compressors.end(); ++compressor)
+           if (compressor->Name == ".")
+              break;
    }
-   else if (Compress != None)
+   else
    {
       std::string name;
       switch (Compress)
       {
+      case None: name = "."; break;
       case Gzip: name = "gzip"; break;
       case Bzip2: name = "bzip2"; break;
       case Lzma: name = "lzma"; break;
       case Xz: name = "xz"; break;
-      default: return _error->Error("Can't find a match for specified compressor mode for file %s", FileName.c_str());
+      case Auto:
+      case Extension:
+        // Unreachable
+        return _error->Error("Opening File %s in None, Auto or Extension should be already handled?!?", FileName.c_str());
       }
       for (; compressor != compressors.end(); ++compressor)
         if (compressor->Name == name)
            break;
-      if (compressor == compressors.end() && name != "gzip")
+      if (compressor == compressors.end())
         return _error->Error("Can't find a configured compressor %s for file %s", name.c_str(), FileName.c_str());
    }
 
-   // if we have them, use inbuilt compressors instead of forking
-   if (compressor != compressors.end())
-   {
-      if (compressor->Name == "gzip")
-      {
-        Compress = Gzip;
-        compressor = compressors.end();
-      }
-      else if (compressor->Name == "." || Compress == None)
-      {
-        Compress = None;
-        compressor = compressors.end();
-      }
-   }
+   if (compressor == compressors.end())
+      return _error->Error("Can't find a match for specified compressor mode for file %s", FileName.c_str());
+   return Open(FileName, Mode, *compressor, Perms);
+}
+bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor, unsigned long const Perms)
+{
+   Close();
+   d = new FileFdPrivate;
+   d->openmode = Mode;
+   Flags = AutoClose;
+
+   if ((Mode & WriteOnly) != WriteOnly && (Mode & (Atomic | Create | Empty | Exclusive)) != 0)
+      return _error->Error("ReadOnly mode for %s doesn't accept additional flags!", FileName.c_str());
+   if ((Mode & ReadWrite) == 0)
+      return _error->Error("No openmode provided in FileFd::Open for %s", FileName.c_str());
 
    if ((Mode & Atomic) == Atomic)
    {
@@ -836,33 +850,33 @@ bool FileFd::Open(string FileName,OpenMode Mode,CompressMode Compress, unsigned
         unlink(FileName.c_str());
    }
 
-   if (compressor != compressors.end())
-   {
-      if ((Mode & ReadWrite) == ReadWrite)
-        _error->Error("External compressors like %s do not support readwrite mode for file %s", compressor->Name.c_str(), FileName.c_str());
+   int fileflags = 0;
+   #define if_FLAGGED_SET(FLAG, MODE) if ((Mode & FLAG) == FLAG) fileflags |= MODE
+   if_FLAGGED_SET(ReadWrite, O_RDWR);
+   else if_FLAGGED_SET(ReadOnly, O_RDONLY);
+   else if_FLAGGED_SET(WriteOnly, O_WRONLY);
 
-      _error->Error("Forking external compressor %s is not implemented for %s", compressor->Name.c_str(), FileName.c_str());
-   }
+   if_FLAGGED_SET(Create, O_CREAT);
+   if_FLAGGED_SET(Empty, O_TRUNC);
+   if_FLAGGED_SET(Exclusive, O_EXCL);
+   else if_FLAGGED_SET(Atomic, O_EXCL);
+   #undef if_FLAGGED_SET
+
+   if (TemporaryFileName.empty() == false)
+      iFd = open(TemporaryFileName.c_str(), fileflags, Perms);
    else
-   {
-      if (TemporaryFileName.empty() == false)
-        iFd = open(TemporaryFileName.c_str(), fileflags, Perms);
-      else
-        iFd = open(FileName.c_str(), fileflags, Perms);
+      iFd = open(FileName.c_str(), fileflags, Perms);
 
+   if (iFd == -1 || OpenInternDescriptor(Mode, compressor) == false)
+   {
       if (iFd != -1)
       {
-        if (OpenInternDescriptor(Mode, Compress) == false)
-        {
-           close (iFd);
-           iFd = -1;
-        }
+        close (iFd);
+        iFd = -1;
       }
+      return _error->Errno("open",_("Could not open file %s"), FileName.c_str());
    }
 
-   if (iFd == -1)
-      return _error->Errno("open",_("Could not open file %s"),FileName.c_str());
-
    this->FileName = FileName;
    SetCloseExec(iFd,true);
    return true;
@@ -871,13 +885,38 @@ bool FileFd::Open(string FileName,OpenMode Mode,CompressMode Compress, unsigned
 // FileFd::OpenDescriptor - Open a filedescriptor                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool FileFd::OpenDescriptor(int Fd, OpenMode Mode, CompressMode Compress, bool AutoClose)
+bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, CompressMode Compress, bool AutoClose)
+{
+   std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
+   std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin();
+   std::string name;
+   switch (Compress)
+   {
+   case None: name = "."; break;
+   case Gzip: name = "gzip"; break;
+   case Bzip2: name = "bzip2"; break;
+   case Lzma: name = "lzma"; break;
+   case Xz: name = "xz"; break;
+   case Auto:
+   case Extension:
+      return _error->Error("Opening Fd %d in Auto or Extension compression mode is not supported", Fd);
+   }
+   for (; compressor != compressors.end(); ++compressor)
+      if (compressor->Name == name)
+        break;
+   if (compressor == compressors.end())
+      return _error->Error("Can't find a configured compressor %s for file %s", name.c_str(), FileName.c_str());
+
+   return OpenDescriptor(Fd, Mode, *compressor, AutoClose);
+}
+bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration::Compressor const &compressor, bool AutoClose)
 {
    Close();
    d = new FileFdPrivate;
+   d->openmode = Mode;
    Flags = (AutoClose) ? FileFd::AutoClose : 0;
    iFd = Fd;
-   if (OpenInternDescriptor(Mode, Compress) == false)
+   if (OpenInternDescriptor(Mode, compressor) == false)
    {
       if (AutoClose)
         close (iFd);
@@ -886,11 +925,13 @@ bool FileFd::OpenDescriptor(int Fd, OpenMode Mode, CompressMode Compress, bool A
    this->FileName = "";
    return true;
 }
-bool FileFd::OpenInternDescriptor(OpenMode Mode, CompressMode Compress)
+bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor)
 {
-   if (Compress == None)
+   d->compressor = compressor;
+   if (compressor.Name == "." || compressor.Binary.empty() == true)
       return true;
-   else if (Compress == Gzip)
+#if APT_USE_ZLIB
+   else if (compressor.Name == "gzip")
    {
       if ((Mode & ReadWrite) == ReadWrite)
         d->gz = gzdopen(iFd, "r+");
@@ -901,9 +942,90 @@ bool FileFd::OpenInternDescriptor(OpenMode Mode, CompressMode Compress)
       if (d->gz == NULL)
         return false;
       Flags |= Compressed;
+      return true;
+   }
+#endif
+
+   if ((Mode & ReadWrite) == ReadWrite)
+      return _error->Error("ReadWrite mode is not supported for file %s", FileName.c_str());
+
+   bool const Comp = (Mode & WriteOnly) == WriteOnly;
+   // Handle 'decompression' of empty files
+   if (Comp == false)
+   {
+      struct stat Buf;
+      fstat(iFd, &Buf);
+      if (Buf.st_size == 0 && S_ISFIFO(Buf.st_mode) == false)
+        return true;
+
+      // We don't need the file open - instead let the compressor open it
+      // as he properly knows better how to efficiently read from 'his' file
+      if (FileName.empty() == false)
+        close(iFd);
    }
+
+   // Create a data pipe
+   int Pipe[2] = {-1,-1};
+   if (pipe(Pipe) != 0)
+      return _error->Errno("pipe",_("Failed to create subprocess IPC"));
+   for (int J = 0; J != 2; J++)
+      SetCloseExec(Pipe[J],true);
+
+   d->compressed_fd = iFd;
+   d->pipe = true;
+
+   if (Comp == true)
+      iFd = Pipe[1];
    else
-      return false;
+      iFd = Pipe[0];
+
+   // The child..
+   d->compressor_pid = ExecFork();
+   if (d->compressor_pid == 0)
+   {
+      if (Comp == true)
+      {
+        dup2(d->compressed_fd,STDOUT_FILENO);
+        dup2(Pipe[0],STDIN_FILENO);
+      }
+      else
+      {
+        if (FileName.empty() == true)
+           dup2(d->compressed_fd,STDIN_FILENO);
+        dup2(Pipe[1],STDOUT_FILENO);
+      }
+
+      SetCloseExec(STDOUT_FILENO,false);
+      SetCloseExec(STDIN_FILENO,false);
+
+      std::vector<char const*> Args;
+      Args.push_back(compressor.Binary.c_str());
+      std::vector<std::string> const * const addArgs =
+               (Comp == true) ? &(compressor.CompressArgs) : &(compressor.UncompressArgs);
+      for (std::vector<std::string>::const_iterator a = addArgs->begin();
+          a != addArgs->end(); ++a)
+        Args.push_back(a->c_str());
+      if (Comp == false && FileName.empty() == false)
+      {
+        Args.push_back("--stdout");
+        if (TemporaryFileName.empty() == false)
+           Args.push_back(TemporaryFileName.c_str());
+        else
+           Args.push_back(FileName.c_str());
+      }
+      Args.push_back(NULL);
+
+      execvp(Args[0],(char **)&Args[0]);
+      cerr << _("Failed to exec compressor ") << Args[0] << endl;
+      _exit(100);
+   }
+   if (Comp == true)
+      close(Pipe[0]);
+   else
+      close(Pipe[1]);
+   if (Comp == true || FileName.empty() == true)
+      close(d->compressed_fd);
+
    return true;
 }
                                                                        /*}}}*/
@@ -926,12 +1048,14 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
    errno = 0;
    if (Actual != 0)
       *Actual = 0;
-   
+   *((char *)To) = '\0';
    do
    {
+#if APT_USE_ZLIB
       if (d->gz != NULL)
          Res = gzread(d->gz,To,Size);
       else
+#endif
          Res = read(iFd,To,Size);
       if (Res < 0 && errno == EINTR)
         continue;
@@ -943,6 +1067,7 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
       
       To = (char *)To + Res;
       Size -= Res;
+      d->seekpos += Res;
       if (Actual != 0)
         *Actual += Res;
    }
@@ -968,8 +1093,11 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
    files because of the naive implementation! */
 char* FileFd::ReadLine(char *To, unsigned long long const Size)
 {
+   *To = '\0';
+#if APT_USE_ZLIB
    if (d->gz != NULL)
       return gzgets(d->gz, To, Size);
+#endif
 
    unsigned long long read = 0;
    if (Read(To, Size, &read) == false)
@@ -993,9 +1121,11 @@ bool FileFd::Write(const void *From,unsigned long long Size)
    errno = 0;
    do
    {
+#if APT_USE_ZLIB
       if (d->gz != NULL)
          Res = gzwrite(d->gz,From,Size);
       else
+#endif
          Res = write(iFd,From,Size);
       if (Res < 0 && errno == EINTR)
         continue;
@@ -1007,6 +1137,7 @@ bool FileFd::Write(const void *From,unsigned long long Size)
       
       From = (char *)From + Res;
       Size -= Res;
+      d->seekpos += Res;
    }
    while (Res > 0 && Size > 0);
    
@@ -1022,17 +1153,55 @@ bool FileFd::Write(const void *From,unsigned long long Size)
 /* */
 bool FileFd::Seek(unsigned long long To)
 {
+   if (d->pipe == true)
+   {
+      // Our poor man seeking in pipes is costly, so try to avoid it
+      unsigned long long seekpos = Tell();
+      if (seekpos == To)
+        return true;
+      else if (seekpos < To)
+        return Skip(To - seekpos);
+
+      if ((d->openmode & ReadOnly) != ReadOnly)
+        return _error->Error("Reopen is only implemented for read-only files!");
+      close(iFd);
+      iFd = 0;
+      if (TemporaryFileName.empty() == false)
+        iFd = open(TemporaryFileName.c_str(), O_RDONLY);
+      else if (FileName.empty() == false)
+        iFd = open(FileName.c_str(), O_RDONLY);
+      else
+      {
+        if (d->compressed_fd > 0)
+           if (lseek(d->compressed_fd, 0, SEEK_SET) != 0)
+              iFd = d->compressed_fd;
+        if (iFd <= 0)
+           return _error->Error("Reopen is not implemented for pipes opened with FileFd::OpenDescriptor()!");
+      }
+
+      if (OpenInternDescriptor(d->openmode, d->compressor) == false)
+        return _error->Error("Seek on file %s because it couldn't be reopened", FileName.c_str());
+
+      if (To != 0)
+        return Skip(To);
+
+      d->seekpos = To;
+      return true;
+   }
    int res;
+#if APT_USE_ZLIB
    if (d->gz)
       res = gzseek(d->gz,To,SEEK_SET);
    else
+#endif
       res = lseek(iFd,To,SEEK_SET);
    if (res != (signed)To)
    {
       Flags |= Fail;
       return _error->Error("Unable to seek to %llu", To);
    }
-   
+
+   d->seekpos = To;
    return true;
 }
                                                                        /*}}}*/
@@ -1042,16 +1211,19 @@ bool FileFd::Seek(unsigned long long To)
 bool FileFd::Skip(unsigned long long Over)
 {
    int res;
+#if APT_USE_ZLIB
    if (d->gz != NULL)
       res = gzseek(d->gz,Over,SEEK_CUR);
    else
+#endif
       res = lseek(iFd,Over,SEEK_CUR);
    if (res < 0)
    {
       Flags |= Fail;
       return _error->Error("Unable to seek ahead %llu",Over);
    }
-   
+   d->seekpos = res;
+
    return true;
 }
                                                                        /*}}}*/
@@ -1079,13 +1251,23 @@ bool FileFd::Truncate(unsigned long long To)
 /* */
 unsigned long long FileFd::Tell()
 {
+   // In theory, we could just return seekpos here always instead of
+   // seeking around, but not all users of FileFd use always Seek() and co
+   // so d->seekpos isn't always true and we can just use it as a hint if
+   // we have nothing else, but not always as an authority…
+   if (d->pipe == true)
+      return d->seekpos;
+
    off_t Res;
+#if APT_USE_ZLIB
    if (d->gz != NULL)
      Res = gztell(d->gz);
    else
+#endif
      Res = lseek(iFd,0,SEEK_CUR);
    if (Res == (off_t)-1)
       _error->Errno("lseek","Failed to determine the current file position");
+   d->seekpos = Res;
    return Res;
 }
                                                                        /*}}}*/
@@ -1095,9 +1277,19 @@ unsigned long long FileFd::Tell()
 unsigned long long FileFd::FileSize()
 {
    struct stat Buf;
-
-   if (fstat(iFd,&Buf) != 0)
+   if (d->pipe == false && fstat(iFd,&Buf) != 0)
       return _error->Errno("fstat","Unable to determine the file size");
+
+   // for compressor pipes st_size is undefined and at 'best' zero
+   if (d->pipe == true || S_ISFIFO(Buf.st_mode))
+   {
+      // we set it here, too, as we get the info here for free
+      // in theory the Open-methods should take care of it already
+      d->pipe = true;
+      if (stat(FileName.c_str(), &Buf) != 0)
+        return _error->Errno("stat","Unable to determine the file size");
+   }
+
    return Buf.st_size;
 }
                                                                        /*}}}*/
@@ -1108,16 +1300,29 @@ unsigned long long FileFd::Size()
 {
    unsigned long long size = FileSize();
 
+   // for compressor pipes st_size is undefined and at 'best' zero,
+   // so we 'read' the content and 'seek' back - see there
+   if (d->pipe == true)
+   {
+      unsigned long long const oldSeek = Tell();
+      char ignore[1000];
+      unsigned long long read = 0;
+      do {
+        Read(ignore, sizeof(ignore), &read);
+      } while(read != 0);
+      size = Tell();
+      Seek(oldSeek);
+   }
+#if APT_USE_ZLIB
    // only check gzsize if we are actually a gzip file, just checking for
    // "gz" is not sufficient as uncompressed files could be opened with
    // gzopen in "direct" mode as well
-   if (d->gz && !gzdirect(d->gz) && size > 0)
+   else if (d->gz && !gzdirect(d->gz) && size > 0)
    {
        /* unfortunately zlib.h doesn't provide a gzsize(), so we have to do
        * this ourselves; the original (uncompressed) file size is the last 32
        * bits of the file */
        // FIXME: Size for gz-files is limited by 32bit… no largefile support
-       off_t orig_pos = lseek(iFd, 0, SEEK_CUR);
        if (lseek(iFd, -4, SEEK_END) < 0)
           return _error->Errno("lseek","Unable to seek to end of gzipped file");
        size = 0L;
@@ -1131,10 +1336,11 @@ unsigned long long FileFd::Size()
        size = tmp_size;
 #endif
 
-       if (lseek(iFd, orig_pos, SEEK_SET) < 0)
+       if (lseek(iFd, d->seekpos, SEEK_SET) < 0)
           return _error->Errno("lseek","Unable to seek in gzipped file");
        return size;
    }
+#endif
 
    return size;
 }
@@ -1145,11 +1351,25 @@ unsigned long long FileFd::Size()
 time_t FileFd::ModificationTime()
 {
    struct stat Buf;
-   if (fstat(iFd,&Buf) != 0)
+   if (d->pipe == false && fstat(iFd,&Buf) != 0)
    {
       _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
       return 0;
    }
+
+   // for compressor pipes st_size is undefined and at 'best' zero
+   if (d->pipe == true || S_ISFIFO(Buf.st_mode))
+   {
+      // we set it here, too, as we get the info here for free
+      // in theory the Open-methods should take care of it already
+      d->pipe = true;
+      if (stat(FileName.c_str(), &Buf) != 0)
+      {
+        _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
+        return 0;
+      }
+   }
+
    return Buf.st_mtime;
 }
                                                                        /*}}}*/
@@ -1164,12 +1384,14 @@ bool FileFd::Close()
    bool Res = true;
    if ((Flags & AutoClose) == AutoClose)
    {
+#if APT_USE_ZLIB
       if (d != NULL && d->gz != NULL) {
         int const e = gzclose(d->gz);
         // gzdopen() on empty files always fails with "buffer error" here, ignore that
         if (e != 0 && e != Z_BUF_ERROR)
            Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
       } else
+#endif
         if (iFd > 0 && close(iFd) != 0)
            Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str());
    }
@@ -1191,6 +1413,8 @@ bool FileFd::Close()
 
    if (d != NULL)
    {
+      if (d->compressor_pid > 0)
+        ExecWait(d->compressor_pid, "FileFdCompressor", true);
       delete d;
       d = NULL;
    }
@@ -1210,4 +1434,5 @@ bool FileFd::Sync()
    return true;
 }
                                                                        /*}}}*/
-gzFile FileFd::gzFd() {return d->gz;};
+
+gzFile FileFd::gzFd() { return (gzFile) d->gz; }