]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
Patchs for apt-cdrom
[apt.git] / apt-pkg / contrib / fileutl.cc
index bfc674c62a58b0c2ca01355d7cb75d1cd834c38b..b5cdf782b064808ff430268e53a8b5c124445f12 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: fileutl.cc,v 1.10 1998/10/20 04:33:16 jgg Exp $
+// $Id: fileutl.cc,v 1.15 1998/11/27 01:14:08 jgg Exp $
 /* ######################################################################
    
    File Utilities
@@ -29,7 +29,7 @@
 // CopyFile - Buffered copy of a file                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* The caller is expected to set things so that failure causes erasure */
-bool CopyFile(FileFd From,FileFd To)
+bool CopyFile(FileFd &From,FileFd &To)
 {
    if (From.IsOpen() == false || To.IsOpen() == false)
       return false;
@@ -119,6 +119,18 @@ string flNotDir(string File)
    return string(File,Res,Res - File.length());
 }
                                                                        /*}}}*/
+// flNotFile - Strip the file from the directory name                  /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string flNotFile(string File)
+{
+   string::size_type Res = File.rfind('/');
+   if (Res == string::npos)
+      return File;
+   Res++;
+   return string(File,0,Res);
+}
+                                                                       /*}}}*/
 // SetCloseExec - Set the close on exec flag                           /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -136,8 +148,8 @@ void SetCloseExec(int Fd,bool Close)
 /* */
 void SetNonBlock(int Fd,bool Block)
 {   
-   int Flags = fcntl(Fd,F_GETFL);
-   if (fcntl(Fd,F_SETFL,(Flags  & ~O_NONBLOCK) | (Block == false)?0:O_NONBLOCK) != 0)
+   int Flags = fcntl(Fd,F_GETFL) & (~O_NONBLOCK);
+   if (fcntl(Fd,F_SETFL,Flags | ((Block == false)?0:O_NONBLOCK)) != 0)
    {
       cerr << "FATAL -> Could not set non-blocking flag " << strerror(errno) << endl;
       exit(100);
@@ -153,8 +165,10 @@ bool WaitFd(int Fd)
    fd_set Set;
    FD_ZERO(&Set);
    FD_SET(Fd,&Set);
+
    if (select(Fd+1,&Set,0,0,0) <= 0)
       return false;
+
    return true;
 }
                                                                        /*}}}*/
@@ -182,19 +196,16 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms)
 
       case WriteAny:
       iFd = open(FileName.c_str(),O_RDWR | O_CREAT,Perms);
-      break;
-      
-      // Dont use this in public directories
-      case LockEmpty:
-      iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_TRUNC,Perms);
-      break;
+      break;      
    }  
 
    if (iFd < 0)
       _error->Errno("open","Could not open file %s",FileName.c_str());
    else
+   {
       this->FileName = FileName;
-   SetCloseExec(iFd,true);
+      SetCloseExec(iFd,true);
+   }   
 }
                                                                        /*}}}*/
 // FileFd::~File - Closes the file                                     /*{{{*/
@@ -223,7 +234,7 @@ bool FileFd::Read(void *To,unsigned long Size)
 // FileFd::Write - Write to the file                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool FileFd::Write(void *From,unsigned long Size)
+bool FileFd::Write(const void *From,unsigned long Size)
 {
    if (write(iFd,From,Size) != (signed)Size)
    {