aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/serialise.cc7
-rw-r--r--src/libutil/types.hh2
-rw-r--r--src/libutil/util.cc17
-rw-r--r--src/libutil/util.hh17
4 files changed, 24 insertions, 19 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 969f638ef..c0e1c17af 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -85,10 +85,11 @@ unsigned int readInt(Source & source)
string readString(Source & source)
{
unsigned int len = readInt(source);
- char buf[len];
- source((unsigned char *) buf, len);
+ unsigned char * buf = new unsigned char[len];
+ AutoDeleteArray<unsigned char> d(buf);
+ source(buf, len);
readPadding(len, source);
- return string(buf, len);
+ return string((char *) buf, len);
}
diff --git a/src/libutil/types.hh b/src/libutil/types.hh
index 1de378961..257871a82 100644
--- a/src/libutil/types.hh
+++ b/src/libutil/types.hh
@@ -44,8 +44,6 @@ public:
newClass(const format & f) : superClass(f) { }; \
};
-MakeError(UsageError, Error)
-
typedef list<string> Strings;
typedef set<string> StringSet;
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 7c1138720..08385e5d9 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -191,18 +191,6 @@ Strings readDirectory(const Path & path)
}
-template <class T>
-struct AutoDeleteArray
-{
- T * p;
- AutoDeleteArray(T * p) : p(p) { }
- ~AutoDeleteArray()
- {
- delete [] p;
- }
-};
-
-
string readFile(int fd)
{
struct stat st;
@@ -468,7 +456,7 @@ void readFull(int fd, unsigned char * buf, size_t count)
if (errno == EINTR) continue;
throw SysError("reading from file");
}
- if (res == 0) throw Error("unexpected end-of-file");
+ if (res == 0) throw EndOfFile("unexpected end-of-file");
count -= res;
buf += res;
}
@@ -707,6 +695,7 @@ int Pid::wait(bool block)
if (res == 0 && !block) return -1;
if (errno != EINTR)
throw SysError("cannot get child exit status");
+ checkInterrupt();
}
}
@@ -793,7 +782,7 @@ void _interrupted()
kills the program! */
if (!std::uncaught_exception()) {
_isInterrupted = 0;
- throw Error("interrupted by the user");
+ throw Interrupted("interrupted by the user");
}
}
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 0d39ffee9..b88508dec 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -139,6 +139,8 @@ extern void (*writeToStderr) (const unsigned char * buf, size_t count);
void readFull(int fd, unsigned char * buf, size_t count);
void writeFull(int fd, const unsigned char * buf, size_t count);
+MakeError(EndOfFile, Error)
+
/* Read a file descriptor until EOF occurs. */
string drainFD(int fd);
@@ -147,6 +149,19 @@ string drainFD(int fd);
/* Automatic cleanup of resources. */
+
+template <class T>
+struct AutoDeleteArray
+{
+ T * p;
+ AutoDeleteArray(T * p) : p(p) { }
+ ~AutoDeleteArray()
+ {
+ delete [] p;
+ }
+};
+
+
class AutoDelete
{
string path;
@@ -229,6 +244,8 @@ void inline checkInterrupt()
if (_isInterrupted) _interrupted();
}
+MakeError(Interrupted, Error)
+
/* String packing / unpacking. */
string packStrings(const Strings & strings);