diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-02-17 23:49:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-02-17 23:49:33 +0100 |
| commit | 25c94845432db88a7ee3db459559eb555b8630b0 (patch) | |
| tree | 148786376d89ecaf92ad09563ec9b192cee03eb6 /src | |
| parent | c27aa600966b2a8f9d9ff9efd545f5866244d195 (diff) | |
Add write_string_to_file().v1.8.97
Diffstat (limited to 'src')
| -rw-r--r-- | src/util.cc | 9 | ||||
| -rw-r--r-- | src/util.h | 1 |
2 files changed, 10 insertions, 0 deletions
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); } @@ -120,6 +120,7 @@ extern int base64_decode (std::string const & in, unsigned char* out, int out_le extern boost::optional<boost::filesystem::path> 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 |
