]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
enhance: Let util::write_file take an std::string_view
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 5 Sep 2022 11:21:33 +0000 (13:21 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 6 Sep 2022 06:13:29 +0000 (08:13 +0200)
src/util/file.cpp
src/util/file.hpp

index e7a2763d6002fb786a0d1a0d1f4b4244992141c5..b933e3d28eba4af8470b0d34d627270b1210c3c2 100644 (file)
@@ -236,7 +236,7 @@ write_fd(int fd, const void* data, size_t size)
 }
 
 nonstd::expected<void, std::string>
-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) {
index fd812cd61951f12bc4ea5a97281a611594aef109..641cdf671bb7b666cccebb0af3bc542179ca31e6 100644 (file)
@@ -26,6 +26,7 @@
 #include <ctime>
 #include <optional>
 #include <string>
+#include <string_view>
 
 namespace util {
 
@@ -52,13 +53,13 @@ void set_timestamps(const std::string& path,
                     std::optional<timespec> mtime = std::nullopt,
                     std::optional<timespec> atime = std::nullopt);
 
-// Write `size` bytes from `data` to `fd`. Returns errno on error.
+// Write `size` bytes from binary `data` to `fd`.
 nonstd::expected<void, std::string>
 write_fd(int fd, const void* data, size_t size);
 
 // Write text `data` to `path`.
 nonstd::expected<void, std::string> write_file(const std::string& path,
-                                               const std::string& data);
+                                               std::string_view data);
 
 // Write binary `data` to `path`.
 nonstd::expected<void, std::string>