summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cdromutl.cc28
-rw-r--r--apt-pkg/contrib/fileutl.cc53
-rw-r--r--apt-pkg/contrib/fileutl.h9
-rw-r--r--apt-pkg/contrib/strutl.cc29
-rw-r--r--apt-pkg/contrib/strutl.h3
5 files changed, 90 insertions, 32 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 7f79e878a..cd8a77aa0 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: cdromutl.cc,v 1.7 1999/07/02 22:21:01 jgg Exp $
+// $Id: cdromutl.cc,v 1.8 1999/07/26 17:46:08 jgg Exp $
/* ######################################################################
CDROM Utilities - Some functions to manipulate CDROM mounts.
@@ -93,18 +93,7 @@ bool UnmountCdrom(string Path)
}
// Wait for mount
- int Status = 0;
- while (waitpid(Child,&Status,0) != Child)
- {
- if (errno == EINTR)
- continue;
- return _error->Errno("waitpid","Couldn't wait for subprocess");
- }
-
- // Check for an error code.
- if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
- return false;
- return true;
+ return ExecWait(Child,"mount",true);
}
/*}}}*/
// MountCdrom - Mount a cdrom /*{{{*/
@@ -142,18 +131,7 @@ bool MountCdrom(string Path)
}
// Wait for mount
- int Status = 0;
- while (waitpid(Child,&Status,0) != Child)
- {
- if (errno == EINTR)
- continue;
- return _error->Errno("waitpid","Couldn't wait for subprocess");
- }
-
- // Check for an error code.
- if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
- return false;
- return true;
+ return ExecWait(Child,"mount",true);
}
/*}}}*/
// IdentCdrom - Generate a unique string for this CD /*{{{*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index c24a216ef..a2c6ab370 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.cc,v 1.29 1999/07/20 05:53:33 jgg Exp $
+// $Id: fileutl.cc,v 1.30 1999/07/26 17:46:08 jgg Exp $
/* ######################################################################
File Utilities
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <signal.h>
+#include <wait.h>
#include <errno.h>
/*}}}*/
@@ -249,6 +250,47 @@ int ExecFork()
return Process;
}
/*}}}*/
+// ExecWait - Fancy waitpid /*{{{*/
+// ---------------------------------------------------------------------
+/* Waits for the given sub process. If Reap is set the no errors are
+ generated. Otherwise a failed subprocess will generate a proper descriptive
+ message */
+bool ExecWait(int Pid,const char *Name,bool Reap)
+{
+ if (Pid <= 1)
+ return true;
+
+ // Wait and collect the error code
+ int Status;
+ while (waitpid(Pid,&Status,0) != Pid)
+ {
+ if (errno == EINTR)
+ continue;
+
+ if (Reap == true)
+ return false;
+
+ return _error->Error("Waited, for %s but it wasn't there",Name);
+ }
+
+
+ // Check for an error code.
+ if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
+ {
+ if (Reap == true)
+ return false;
+ if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV)
+ return _error->Error("Sub-process %s recieved a segmentation fault.",Name);
+
+ if (WIFEXITED(Status) != 0)
+ return _error->Error("Sub-process %s returned an error code (%u)",Name,WEXITSTATUS(Status));
+
+ return _error->Error("Sub-process %s exited unexpectedly",Name);
+ }
+
+ return true;
+}
+ /*}}}*/
// FileFd::Open - Open a file /*{{{*/
// ---------------------------------------------------------------------
@@ -302,7 +344,7 @@ FileFd::~FileFd()
// ---------------------------------------------------------------------
/* We are carefull to handle interruption by a signal while reading
gracefully. */
-bool FileFd::Read(void *To,unsigned long Size)
+bool FileFd::Read(void *To,unsigned long Size,bool AllowEof)
{
int Res;
errno = 0;
@@ -325,6 +367,13 @@ bool FileFd::Read(void *To,unsigned long Size)
if (Size == 0)
return true;
+ // Eof handling
+ if (AllowEof == true)
+ {
+ Flags |= HitEof;
+ return true;
+ }
+
Flags |= Fail;
return _error->Error("read, still have %u to read but none left",Size);
}
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 1186fb283..fe904acf5 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.h,v 1.20 1999/07/20 05:53:33 jgg Exp $
+// $Id: fileutl.h,v 1.21 1999/07/26 17:46:08 jgg Exp $
/* ######################################################################
File Utilities
@@ -32,14 +32,15 @@ class FileFd
protected:
int iFd;
- enum LocalFlags {AutoClose = (1<<0),Fail = (1<<1),DelOnFail = (1<<2)};
+ enum LocalFlags {AutoClose = (1<<0),Fail = (1<<1),DelOnFail = (1<<2),
+ HitEof = (1<<3)};
unsigned long Flags;
string FileName;
public:
enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny};
- bool Read(void *To,unsigned long Size);
+ bool Read(void *To,unsigned long Size,bool AllowEof = false);
bool Write(const void *From,unsigned long Size);
bool Seek(unsigned long To);
bool Skip(unsigned long To);
@@ -56,6 +57,7 @@ class FileFd
inline bool Failed() {return (Flags & Fail) == Fail;};
inline void EraseOnFailure() {Flags |= DelOnFail;};
inline void OpFail() {Flags |= Fail;};
+ inline bool Eof() {return (Flags & HitEof) == HitEof;};
inline string &Name() {return FileName;};
FileFd(string FileName,OpenMode Mode,unsigned long Perms = 0666) : iFd(-1),
@@ -76,6 +78,7 @@ void SetCloseExec(int Fd,bool Close);
void SetNonBlock(int Fd,bool Block);
bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
int ExecFork();
+bool ExecWait(int Pid,const char *Name,bool Reap = false);
// File string manipulators
string flNotDir(string File);
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 6c3009462..fb5f6683c 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.cc,v 1.26 1999/06/27 04:55:54 jgg Exp $
+// $Id: strutl.cc,v 1.27 1999/07/26 17:46:08 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -666,6 +666,33 @@ bool StrToTime(string Val,time_t &Result)
return true;
}
/*}}}*/
+// StrToNum - Convert a fixed length string to a number /*{{{*/
+// ---------------------------------------------------------------------
+/* This is used in decoding the crazy fixed length string headers in
+ tar and ar files. */
+bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base)
+{
+ char S[30];
+ if (Len >= sizeof(S))
+ return false;
+ memcpy(S,Str,Len);
+ S[Len] = 0;
+
+ // All spaces is a zero
+ Res = 0;
+ unsigned I;
+ for (I = 0; S[I] == ' '; I++);
+ if (S[I] == 0)
+ return true;
+
+ char *End;
+ Res = strtoul(S,&End,Base);
+ if (End == S)
+ return false;
+
+ return true;
+}
+ /*}}}*/
// URI::CopyFrom - Copy from an object /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 2f2629985..6ba1f9ebe 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.h,v 1.13 1999/05/27 05:54:41 jgg Exp $
+// $Id: strutl.h,v 1.14 1999/07/26 17:46:08 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -41,6 +41,7 @@ bool StrToTime(string Val,time_t &Result);
string LookupTag(string Message,const char *Tag,const char *Default = 0);
int StringToBool(string Text,int Default = -1);
bool ReadMessages(int Fd, vector<string> &List);
+bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};