From 25c94845432db88a7ee3db459559eb555b8630b0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 17 Feb 2024 23:49:33 +0100 Subject: Add write_string_to_file(). --- src/util.cc | 9 +++++++++ src/util.h | 1 + 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/util.cc b/src/util.cc index f5a15944..a920ce0e 100644 --- a/src/util.cc +++ b/src/util.cc @@ -272,6 +272,15 @@ dcp::file_to_string (boost::filesystem::path p, uintmax_t max_length) } +void +dcp::write_string_to_file(string const& string, boost::filesystem::path const& path) +{ + File file(path, "w"); + if (!file) { + throw FileError("could not open file", path, errno); + } + + file.write(string.c_str(), string.length(), 1); } diff --git a/src/util.h b/src/util.h index 551eed07..585166e3 100644 --- a/src/util.h +++ b/src/util.h @@ -120,6 +120,7 @@ extern int base64_decode (std::string const & in, unsigned char* out, int out_le extern boost::optional relative_to_root (boost::filesystem::path root, boost::filesystem::path file); extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length = 1048576); +extern void write_string_to_file(std::string const& string, boost::filesystem::path const& path); /** @param key RSA private key in PEM format (optionally with -----BEGIN... / -----END...) * @return SHA1 fingerprint of key -- cgit v1.2.3