From: Carl Hetherington Date: Sat, 17 Feb 2024 22:49:33 +0000 (+0100) Subject: Add write_string_to_file(). X-Git-Tag: v1.8.97 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;ds=sidebyside;h=25c94845432db88a7ee3db459559eb555b8630b0;p=libdcp.git Add write_string_to_file(). --- 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