aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/file-system.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-05-03 22:53:24 +0200
committereldritch horrors <pennae@lix.systems>2024-06-19 10:50:12 +0000
commit11f4a5bc7eca8a4cca2ae9f3d83b69cd497933f8 (patch)
treeb991157e020697bb4f05ad4629298b183cb5ed61 /src/libutil/file-system.cc
parent67f778670c085615470b67eb3c54885b8c2d482e (diff)
libutil: return a source from readFile
don't consume a sink, return a source instead. the only reason to not do this is a very slight reduction in dynamic allocations, but since we are going to *at least* do disk io that will not be a lot of overhead anyway Change-Id: Iae2f879ec64c3c3ac1d5310eeb6a85e696d4614a
Diffstat (limited to 'src/libutil/file-system.cc')
-rw-r--r--src/libutil/file-system.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc
index d573b22b4..f51f3c092 100644
--- a/src/libutil/file-system.cc
+++ b/src/libutil/file-system.cc
@@ -289,12 +289,17 @@ std::string readFile(const Path & path)
}
-void readFile(const Path & path, Sink & sink)
+box_ptr<Source> readFileSource(const Path & path)
{
AutoCloseFD fd{open(path.c_str(), O_RDONLY | O_CLOEXEC)};
if (!fd)
throw SysError("opening file '%s'", path);
- drainFD(fd.get(), sink);
+
+ struct FileSource : FdSource {
+ AutoCloseFD fd;
+ explicit FileSource(AutoCloseFD fd) : FdSource(fd.get()), fd(std::move(fd)) {}
+ };
+ return make_box_ptr<FileSource>(std::move(fd));
}