diff options
author | Tea <tea.desouza@gmail.com> | 2015-11-07 14:09:59 +0800 |
---|---|---|
committer | Tea <tea.desouza@gmail.com> | 2015-11-10 10:03:41 +0800 |
commit | 29f6670f11c4ac505cad0f779430dea01358c025 (patch) | |
tree | 87b6edec647fb24a863b906b60966c98c4ad3dc1 /include | |
parent | 5a302a2b3b291692b8f5e9cb70d3bad61ef22064 (diff) | |
download | caffeonacl-29f6670f11c4ac505cad0f779430dea01358c025.tar.gz caffeonacl-29f6670f11c4ac505cad0f779430dea01358c025.tar.bz2 caffeonacl-29f6670f11c4ac505cad0f779430dea01358c025.zip |
Replace unistd functions with cross platform counterparts
Diffstat (limited to 'include')
-rw-r--r-- | include/caffe/util/io.hpp | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/include/caffe/util/io.hpp b/include/caffe/util/io.hpp index d6cfa442..6b733254 100644 --- a/include/caffe/util/io.hpp +++ b/include/caffe/util/io.hpp @@ -1,7 +1,7 @@ #ifndef CAFFE_UTIL_IO_H_ #define CAFFE_UTIL_IO_H_ -#include <unistd.h> +#include <boost/filesystem.hpp> #include <string> #include "google/protobuf/message.h" @@ -12,31 +12,23 @@ namespace caffe { using ::google::protobuf::Message; +using ::boost::filesystem::path; inline void MakeTempFilename(string* temp_filename) { temp_filename->clear(); - *temp_filename = "/tmp/caffe_test.XXXXXX"; - char* temp_filename_cstr = new char[temp_filename->size() + 1]; - // NOLINT_NEXT_LINE(runtime/printf) - strcpy(temp_filename_cstr, temp_filename->c_str()); - int fd = mkstemp(temp_filename_cstr); - CHECK_GE(fd, 0) << "Failed to open a temporary file at: " << *temp_filename; - close(fd); - *temp_filename = temp_filename_cstr; - delete[] temp_filename_cstr; + const path& model = boost::filesystem::temp_directory_path() + /"caffe_test.%%%%%%"; + *temp_filename = boost::filesystem::unique_path(model).string(); } inline void MakeTempDir(string* temp_dirname) { temp_dirname->clear(); - *temp_dirname = "/tmp/caffe_test.XXXXXX"; - char* temp_dirname_cstr = new char[temp_dirname->size() + 1]; - // NOLINT_NEXT_LINE(runtime/printf) - strcpy(temp_dirname_cstr, temp_dirname->c_str()); - char* mkdtemp_result = mkdtemp(temp_dirname_cstr); - CHECK(mkdtemp_result != NULL) - << "Failed to create a temporary directory at: " << *temp_dirname; - *temp_dirname = temp_dirname_cstr; - delete[] temp_dirname_cstr; + const path& model = boost::filesystem::temp_directory_path() + /"caffe_test.%%%%%%"; + const path& dir = boost::filesystem::unique_path(model).string(); + bool directoryCreated = boost::filesystem::create_directory(dir); + CHECK(directoryCreated); + *temp_dirname = dir.string(); } bool ReadProtoFromTextFile(const char* filename, Message* proto); |