summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Buffer.h1
-rw-r--r--include/Exceptions.h3
-rw-r--r--include/InPipe.h1
-rw-r--r--include/Input.h1
-rw-r--r--include/OutPipe.h1
-rw-r--r--include/Output.h1
-rw-r--r--lib/Buffer.cc5
-rw-r--r--lib/Exceptions.cc7
-rw-r--r--lib/Handle.cc4
-rw-r--r--lib/InPipe.cc5
-rw-r--r--lib/Input.cc3
-rw-r--r--lib/OutPipe.cc5
-rw-r--r--lib/Output.cc3
13 files changed, 37 insertions, 3 deletions
diff --git a/include/Buffer.h b/include/Buffer.h
index 53a3131..360abad 100644
--- a/include/Buffer.h
+++ b/include/Buffer.h
@@ -13,6 +13,7 @@
class Buffer : public Handle {
public:
Buffer();
+ Buffer(const Buffer &);
virtual ~Buffer();
virtual ssize_t write(const void *buf, size_t count);
virtual ssize_t read(void *buf, size_t count) throw (GeneralException);
diff --git a/include/Exceptions.h b/include/Exceptions.h
index e5d24e6..1b98598 100644
--- a/include/Exceptions.h
+++ b/include/Exceptions.h
@@ -13,6 +13,7 @@ class GeneralException;
char * xstrdup(const char *);
void * xmalloc(size_t) throw (GeneralException);
void xfree(void *&);
+void xfree(char *&);
void * xrealloc(void *, size_t);
int xpipe(int *, int = 0) throw (GeneralException);
pid_t xfork() throw (GeneralException);
@@ -46,7 +47,7 @@ class Base {
xfree(p);
}
static void free(char *& p) {
- xfree((void *) p);
+ xfree(p);
}
static int pipe(int * p, int flag = 0) {
return xpipe(p, flag);
diff --git a/include/InPipe.h b/include/InPipe.h
index 251523d..fa14868 100644
--- a/include/InPipe.h
+++ b/include/InPipe.h
@@ -7,6 +7,7 @@
class InPipe : public Handle {
public:
InPipe();
+ InPipe(const InPipe &);
virtual ~InPipe();
void Hook();
virtual bool CanWrite();
diff --git a/include/Input.h b/include/Input.h
index 87190f1..7091258 100644
--- a/include/Input.h
+++ b/include/Input.h
@@ -10,6 +10,7 @@
class Input : public Handle {
public:
Input(String = "") throw (GeneralException);
+ Input(const Input &);
virtual ~Input() {}
virtual bool CanWrite();
virtual bool CanRead();
diff --git a/include/OutPipe.h b/include/OutPipe.h
index 9861d6d..4a9befe 100644
--- a/include/OutPipe.h
+++ b/include/OutPipe.h
@@ -7,6 +7,7 @@
class OutPipe : public Handle {
public:
OutPipe();
+ OutPipe(const OutPipe &);
virtual ~OutPipe();
void Hook();
virtual bool CanWrite();
diff --git a/include/Output.h b/include/Output.h
index 6c4fdec..32d4e66 100644
--- a/include/Output.h
+++ b/include/Output.h
@@ -8,6 +8,7 @@
class Output : public Handle {
public:
Output(String = "", int trunc = 1) throw (GeneralException);
+ Output(const Output &);
virtual ~Output() {}
virtual bool CanWrite();
virtual bool CanRead();
diff --git a/lib/Buffer.cc b/lib/Buffer.cc
index e8335d9..83369bd 100644
--- a/lib/Buffer.cc
+++ b/lib/Buffer.cc
@@ -9,6 +9,11 @@ Buffer::~Buffer() {
free(buffer);
}
+Buffer::Buffer(const Buffer & b) : Handle(-1), buffer(0), zero(b.zero), realsiz(b.realsiz), bufsiz(b.bufsiz), ptr(b.ptr) {
+ buffer = (char *) malloc(bufsiz);
+ memcpy(buffer, b.buffer, bufsiz);
+}
+
ssize_t Buffer::write(const void *buf, size_t count) {
if (!count) {
return 0;
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc
index 1283f6a..7c9d318 100644
--- a/lib/Exceptions.cc
+++ b/lib/Exceptions.cc
@@ -118,6 +118,13 @@ void xfree(void *& p) {
}
}
+void xfree(char *& p) {
+ if (p) {
+ ::free(p - sizeof(size_t));
+ p = 0;
+ }
+}
+
int xpipe(int * p, int flag) throw (GeneralException) {
if (pipe(p)) {
throw GeneralException(String(_("Error creating pipe: ")) + strerror(errno));
diff --git a/lib/Handle.cc b/lib/Handle.cc
index 6c3bbbd..fe7c10b 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -6,7 +6,7 @@
#include "Handle.h"
#include "config.h"
-Handle::Handle(const Handle & nh) : h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(false), nonblock(false), zfile(0), z(0) {
+Handle::Handle(const Handle & nh) : h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(nh.closed), nonblock(nh.closed), zfile(0), z(0) {
// cerr << "Duplication of handle " << nh.h << " to " << h << endl;
if ((h >= 0) && (nh.z)) {
SetZ(nh.z);
@@ -18,7 +18,7 @@ Handle::~Handle() {
close();
}
-Handle::Handle(int nh) : h(nh), closed(false), zfile(0), z(0) {
+Handle::Handle(int nh) : h(nh), closed(false), nonblock(false), zfile(0), z(0) {
// cerr << "Initialising handle " << h << endl;
}
diff --git a/lib/InPipe.cc b/lib/InPipe.cc
index 978d24b..c61005f 100644
--- a/lib/InPipe.cc
+++ b/lib/InPipe.cc
@@ -4,6 +4,11 @@
InPipe::InPipe() : Handle(pipe(p, 0)), hooked(0) { }
+InPipe::InPipe(const InPipe & i) : Handle(i), hooked(i.hooked) {
+ p[0] = GetHandle();
+ p[1] = dup(i.p[1]);
+}
+
InPipe::~InPipe() {
if (hooked) {
::close(1);
diff --git a/lib/Input.cc b/lib/Input.cc
index 318821d..5652c57 100644
--- a/lib/Input.cc
+++ b/lib/Input.cc
@@ -26,6 +26,9 @@ Input::Input(String no) throw (GeneralException) :
date_modif = s.st_mtime;
}
+Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) {
+}
+
bool Input::CanWrite() {
return 0;
}
diff --git a/lib/OutPipe.cc b/lib/OutPipe.cc
index 4b2e710..be93e15 100644
--- a/lib/OutPipe.cc
+++ b/lib/OutPipe.cc
@@ -11,6 +11,11 @@ OutPipe::~OutPipe() {
}
}
+OutPipe::OutPipe(const OutPipe & o) : Handle(o), hooked(o.hooked) {
+ p[0] = dup(i.p[0]);
+ p[1] = GetHandle();
+}
+
void OutPipe::Hook() {
if (!hooked) {
hooked = 1;
diff --git a/lib/Output.cc b/lib/Output.cc
index 27f28d2..deecfb0 100644
--- a/lib/Output.cc
+++ b/lib/Output.cc
@@ -17,6 +17,9 @@ Output::Output(String no, int trunc = 1) throw (GeneralException) :
}
}
+Output::Output(const Output & o) : Handle(o), n(o.n) {
+}
+
bool Output::CanWrite() {
return 1;
}