summaryrefslogtreecommitdiffstats
path: root/file.hpp
diff options
context:
space:
mode:
authorRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2017-12-16 15:11:47 +0530
committerRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-01-19 11:47:03 +0530
commit1f5a002f4b596522cf46eaad3cfd072a44b5848d (patch)
treec4d189aa8f6afd5395e36bddfce10be95695dcda /file.hpp
parent035a96983cdf8a11a1c2380106c11c94cb8418b2 (diff)
downloadphosphor-user-manager-1f5a002f4b596522cf46eaad3cfd072a44b5848d.tar.gz
phosphor-user-manager-1f5a002f4b596522cf46eaad3cfd072a44b5848d.zip
Fix to use mkstemp for temp shadow file creation
Do not rely on randomString() for tempShadowFile, as it uses '/' in random set, and cause file creation error. Also, it's safe to use mkstemp to create temp shadow file with random name suffixing shadow file name. Change-Id: I0b80cc6d7c002e732e22f660e50b0701acac15fe Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'file.hpp')
-rw-r--r--file.hpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/file.hpp b/file.hpp
index ae5cf85..7b22b3e 100644
--- a/file.hpp
+++ b/file.hpp
@@ -49,6 +49,23 @@ class File
fp = fopen(name.c_str(), mode.c_str());
}
+ /** @brief Opens file using provided file descriptor
+ *
+ * @param[in] fd - File descriptor
+ * @param[in] name - File name
+ * @param[in] mode - File open mode
+ * @param[in] removeOnExit - File to be removed at exit or no
+ */
+ File(int fd,
+ const std::string& name,
+ const std::string& mode,
+ bool removeOnExit = false) :
+ name(name),
+ removeOnExit(removeOnExit)
+ {
+ fp = fdopen(fd, mode.c_str());
+ }
+
~File()
{
if (fp)
OpenPOWER on IntegriCloud