From a37338815de6affd44f927712143f626c8e6d79d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 1 Feb 2005 22:07:48 +0000 Subject: * A GC setting `gc-keep-outputs' to specify whether output paths of derivations should be kept. --- src/libutil/util.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/libutil/util.cc') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 108c054b7f41..2fb3e9ee6853 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -164,6 +164,27 @@ Strings readDirectory(const Path & path) } +string readFile(int fd) +{ + struct stat st; + if (fstat(fd, &st) == -1) + throw SysError("statting file"); + unsigned char buf[st.st_size]; /* !!! stack space */ + readFull(fd, buf, st.st_size); + + return string((char *) buf, st.st_size); +} + + +string readFile(const Path & path) +{ + AutoCloseFD fd = open(path.c_str(), O_RDONLY); + if (fd == -1) + throw SysError(format("opening file `%1%'") % path); + return readFile(fd); +} + + static void _deletePath(const Path & path) { checkInterrupt(); -- cgit 1.4.1