aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2009-03-28 19:29:55 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2009-03-28 19:29:55 +0000
commit3a2bbe7f8ad7ec8b2896ff5e666b8f5525691c6f (patch)
tree6c0b4a12f499f2cb6d1c0cc0f199cad0239b1566 /src/libutil/util.cc
parent7fb548aa2621375559f980b4627955dbc6fe9914 (diff)
* Simplify communication with the hook a bit (don't use file
descriptors 3/4, just use stdin/stderr).
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 02dd53a17..1cb94215e 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -229,6 +229,33 @@ void writeFile(const Path & path, const string & s)
}
+string readLine(int fd)
+{
+ string s;
+ while (1) {
+ checkInterrupt();
+ char ch;
+ ssize_t rd = read(fd, &ch, 1);
+ if (rd == -1) {
+ if (errno != EINTR)
+ throw SysError("reading a line");
+ } else if (rd == 0)
+ throw Error("unexpected EOF reading a line");
+ else {
+ if (ch == '\n') return s;
+ s += ch;
+ }
+ }
+}
+
+
+void writeLine(int fd, string s)
+{
+ s += '\n';
+ writeFull(fd, (const unsigned char *) s.c_str(), s.size());
+}
+
+
static void _computePathSize(const Path & path,
unsigned long long & bytes, unsigned long long & blocks)
{