From: Joel Rosdahl Date: Mon, 5 Sep 2022 11:21:33 +0000 (+0200) Subject: enhance: Let util::write_file take an std::string_view X-Git-Tag: v4.7~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63938c5661ecf559bc6e8e02b71162dff00ef7a9;p=thirdparty%2Fccache.git enhance: Let util::write_file take an std::string_view --- diff --git a/src/util/file.cpp b/src/util/file.cpp index e7a2763d6..b933e3d28 100644 --- a/src/util/file.cpp +++ b/src/util/file.cpp @@ -236,7 +236,7 @@ write_fd(int fd, const void* data, size_t size) } nonstd::expected -write_file(const std::string& path, const std::string& data) +write_file(const std::string& path, std::string_view data) { Fd fd(open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_TEXT, 0666)); if (!fd) { diff --git a/src/util/file.hpp b/src/util/file.hpp index fd812cd61..641cdf671 100644 --- a/src/util/file.hpp +++ b/src/util/file.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace util { @@ -52,13 +53,13 @@ void set_timestamps(const std::string& path, std::optional mtime = std::nullopt, std::optional atime = std::nullopt); -// Write `size` bytes from `data` to `fd`. Returns errno on error. +// Write `size` bytes from binary `data` to `fd`. nonstd::expected write_fd(int fd, const void* data, size_t size); // Write text `data` to `path`. nonstd::expected write_file(const std::string& path, - const std::string& data); + std::string_view data); // Write binary `data` to `path`. nonstd::expected