diff options
author | Kenneth Heafield <github@kheafield.com> | 2012-08-06 22:35:24 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2012-08-06 22:35:24 +0400 |
commit | cba50df899809ede5e2d85b63bfc461ed2bae83c (patch) | |
tree | 47a401379671bc113843ef133604a8e322de587e /util | |
parent | b52ed110b02dff440512ee241211f7f0238e82d1 (diff) |
Maybe if I make TempMaker provide the file name, people will stop using tmpnam.
Diffstat (limited to 'util')
-rw-r--r-- | util/file.cc | 14 | ||||
-rw-r--r-- | util/file.hh | 4 |
2 files changed, 10 insertions, 8 deletions
diff --git a/util/file.cc b/util/file.cc index 98f139837..29eaa7b50 100644 --- a/util/file.cc +++ b/util/file.cc @@ -266,16 +266,18 @@ mkstemp_and_unlink(char *tmpl) { } #endif -int TempMaker::Make() const { - std::string copy(base_); - copy.push_back(0); +int TempMaker::Make(std::string *out_name) const { + std::string other; + if (!out_name) out_name = &other; + *out_name = base_; + out_name->push_back(0); int ret; - UTIL_THROW_IF(-1 == (ret = mkstemp_and_unlink(©[0])), util::ErrnoException, "Failed to make a temporary based on " << base_); + UTIL_THROW_IF(-1 == (ret = mkstemp_and_unlink(&(*out_name)[0])), util::ErrnoException, "Failed to make a temporary based on " << base_); return ret; } -std::FILE *TempMaker::MakeFile() const { - util::scoped_fd file(Make()); +std::FILE *TempMaker::MakeFile(std::string *out_name) const { + util::scoped_fd file(Make(out_name)); return FDOpenOrThrow(file); } diff --git a/util/file.hh b/util/file.hh index 72c8ea768..cc986270c 100644 --- a/util/file.hh +++ b/util/file.hh @@ -94,9 +94,9 @@ class TempMaker { public: explicit TempMaker(const std::string &prefix); - int Make() const; + int Make(std::string *out_name = NULL) const; - std::FILE *MakeFile() const; + std::FILE *MakeFile(std::string *out_name = NULL) const; private: std::string base_; |