diff options
author | Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com> | 2018-05-24 10:49:10 +0530 |
---|---|---|
committer | Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com> | 2018-09-03 14:16:20 +0530 |
commit | 9f630d9eb0ce1c103532a4304ea080066199094e (patch) | |
tree | b102a63e2617d928ce82215b07637336ded2db7d /file.hpp | |
parent | 10eb23f8d64d197dade920178b193c1979235156 (diff) | |
download | phosphor-user-manager-9f630d9eb0ce1c103532a4304ea080066199094e.tar.gz phosphor-user-manager-9f630d9eb0ce1c103532a4304ea080066199094e.zip |
Basic support for User manager service
Basic support for User Manager service methods
are implemented.
Change-Id: Id42432ec6dd421b99971268add931dcd70876f7c
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'file.hpp')
-rw-r--r-- | file.hpp | 113 |
1 files changed, 55 insertions, 58 deletions
@@ -15,75 +15,72 @@ namespace fs = std::experimental::filesystem; */ class File { - private: - /** @brief handler for operating on file */ - FILE *fp = NULL; + private: + /** @brief handler for operating on file */ + FILE* fp = NULL; - /** @brief File name. Needed in the case where the temp - * needs to be removed - */ - const std::string& name; + /** @brief File name. Needed in the case where the temp + * needs to be removed + */ + const std::string& name; - /** @brief Should the file be removed at exit */ - bool removeOnExit = false; + /** @brief Should the file be removed at exit */ + bool removeOnExit = false; - public: - File() = delete; - File(const File&) = delete; - File& operator=(const File&) = delete; - File(File&&) = delete; - File& operator=(File&&) = delete; + public: + File() = delete; + File(const File&) = delete; + File& operator=(const File&) = delete; + File(File&&) = delete; + File& operator=(File&&) = delete; - /** @brief Opens file and uses it to do file operation - * - * @param[in] name - File name - * @param[in] mode - File open mode - * @param[in] removeOnExit - File to be removed at exit or no - */ - File(const std::string& name, - const std::string& mode, - bool removeOnExit = false) : - name(name), - removeOnExit(removeOnExit) - { - fp = fopen(name.c_str(), mode.c_str()); - } + /** @brief Opens file and uses it to do file operation + * + * @param[in] name - File name + * @param[in] mode - File open mode + * @param[in] removeOnExit - File to be removed at exit or no + */ + File(const std::string& name, const std::string& mode, + bool removeOnExit = false) : + name(name), + removeOnExit(removeOnExit) + { + 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()); - } + /** @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() + ~File() + { + if (fp) { - if (fp) - { - fclose(fp); - } - - // Needed for exception safety - if (removeOnExit && fs::exists(name)) - { - fs::remove(name); - } + fclose(fp); } - auto operator()() + // Needed for exception safety + if (removeOnExit && fs::exists(name)) { - return fp; + fs::remove(name); } + } + + auto operator()() + { + return fp; + } }; } // namespace user |