]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
* Fixed German translations of "Suggested" from Christi...
[apt.git] / apt-pkg / contrib / fileutl.cc
index db878064d8c02b233a8ef43546d30ef9eb758e0a..4ba8ab05aa815f0ba303b8ebbd4d03f5b575ecdb 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: fileutl.cc,v 1.37 2001/03/03 22:45:59 tausq Exp $
+// $Id: fileutl.cc,v 1.42 2002/09/14 05:29:22 jgg Exp $
 /* ######################################################################
    
    File Utilities
@@ -9,7 +9,7 @@
    GetLock - dpkg compatible lock file manipulation (fcntl)
    
    This source is placed in the Public Domain, do with it what you will
-   It was originally written by Jason Gunthorpe.
+   It was originally written by Jason Gunthorpe <jgg@debian.org>.
    
    ##################################################################### */
                                                                        /*}}}*/
@@ -23,6 +23,7 @@
 
 #include <apti18n.h>
 
+#include <iostream>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -33,6 +34,8 @@
 #include <errno.h>
                                                                        /*}}}*/
 
+using namespace std;
+
 // CopyFile - Buffered copy of a file                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* The caller is expected to set things so that failure causes erasure */
@@ -153,12 +156,12 @@ string flNotDir(string File)
                                                                        /*}}}*/
 // flNotFile - Strip the file from the directory name                  /*{{{*/
 // ---------------------------------------------------------------------
-/* */
+/* Result ends in a / */
 string flNotFile(string File)
 {
    string::size_type Res = File.rfind('/');
    if (Res == string::npos)
-      return File;
+      return "./";
    Res++;
    return string(File,0,Res);
 }
@@ -334,7 +337,7 @@ int ExecFork()
                                                                        /*}}}*/
 // ExecWait - Fancy waitpid                                            /*{{{*/
 // ---------------------------------------------------------------------
-/* Waits for the given sub process. If Reap is set the no errors are 
+/* Waits for the given sub process. If Reap is set then no errors are 
    generated. Otherwise a failed subprocess will generate a proper descriptive
    message */
 bool ExecWait(int Pid,const char *Name,bool Reap)
@@ -431,10 +434,13 @@ FileFd::~FileFd()
 // ---------------------------------------------------------------------
 /* We are carefull to handle interruption by a signal while reading 
    gracefully. */
-bool FileFd::Read(void *To,unsigned long Size,bool AllowEof)
+bool FileFd::Read(void *To,unsigned long Size,unsigned long *Actual)
 {
    int Res;
    errno = 0;
+   if (Actual != 0)
+      *Actual = 0;
+   
    do
    {
       Res = read(iFd,To,Size);
@@ -448,6 +454,8 @@ bool FileFd::Read(void *To,unsigned long Size,bool AllowEof)
       
       To = (char *)To + Res;
       Size -= Res;
+      if (Actual != 0)
+        *Actual += Res;
    }
    while (Res > 0 && Size > 0);
    
@@ -455,7 +463,7 @@ bool FileFd::Read(void *To,unsigned long Size,bool AllowEof)
       return true;
    
    // Eof handling
-   if (AllowEof == true)
+   if (Actual != 0)
    {
       Flags |= HitEof;
       return true;