]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
Minor fixes for FTP support
[apt.git] / apt-pkg / contrib / fileutl.cc
index f34d839e3f0072e5f2e5fc900a9d7888e0b91d04..a761794eefd4d4ad6764cc0d1a4d9fca99ed394f 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: fileutl.cc,v 1.19 1999/02/08 07:30:50 jgg Exp $
+// $Id: fileutl.cc,v 1.22 1999/03/15 08:10:39 jgg Exp $
 /* ######################################################################
    
    File Utilities
@@ -24,6 +24,7 @@
 #include <sys/stat.h>
 #include <sys/fcntl.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <errno.h>
                                                                        /*}}}*/
 
@@ -163,16 +164,27 @@ void SetNonBlock(int Fd,bool Block)
 // WaitFd - Wait for a FD to become readable                           /*{{{*/
 // ---------------------------------------------------------------------
 /* This waits for a FD to become readable using select. It is usefull for
-   applications making use of non-blocking sockets. */
-bool WaitFd(int Fd)
+   applications making use of non-blocking sockets. The timeout is 
+   in seconds. */
+bool WaitFd(int Fd,bool write,unsigned long timeout)
 {
    fd_set Set;
+   struct timeval tv;
    FD_ZERO(&Set);
    FD_SET(Fd,&Set);
-
-   if (select(Fd+1,&Set,0,0,0) <= 0)
-      return false;
-
+   tv.tv_sec = timeout;
+   tv.tv_usec = 0;
+   if (write == true) 
+   {
+      if (select(Fd+1,0,&Set,0,(timeout != 0?&tv:0)) <= 0)
+         return false;
+   } 
+   else 
+   {
+      if (select(Fd+1,&Set,0,0,(timeout != 0?&tv:0)) <= 0)
+         return false;
+   }
+   
    return true;
 }
                                                                        /*}}}*/
@@ -264,6 +276,20 @@ bool FileFd::Seek(unsigned long To)
       return _error->Error("Unable to seek to %u",To);
    }
    
+   return true;
+}
+                                                                       /*}}}*/
+// FileFd::Truncate - Truncate the file                                /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool FileFd::Truncate(unsigned long To)
+{
+   if (ftruncate(iFd,To) != 0)
+   {
+      Flags |= Fail;
+      return _error->Error("Unable to truncate to %u",To);
+   }
+   
    return true;
 }
                                                                        /*}}}*/