[Common] Added safe method to obtain string representation of system error codes.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 11 Jun 2015 11:20:30 +0000 (13:20 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 11 Jun 2015 11:21:34 +0000 (13:21 +0200)
Change-Id: I02258f8b372610c03cced417a63163c07c251e5c
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/common/tools.cc
src/common/tools.h

index 711bb8f..679f2c0 100644 (file)
@@ -274,5 +274,12 @@ PlatformResult CheckAccess(const std::vector<std::string>& privileges) {
   }
 }
 
+std::string GetErrorString(int error_code) {
+  static const size_t kSize = 1024;
+  char msg[kSize] = {0};
+  strerror_r(error_code, msg, kSize);
+  return msg;
+}
+
 }  // namespace tools
 }  // namespace common
index fecdea6..56b9a8a 100644 (file)
@@ -60,6 +60,15 @@ do { \
   } \
 } while (0)
 
+/**
+ * @brief Safe wrapper of strerror() function.
+ *
+ * @param[in] error_code - error code to be passed to strerror()
+ *
+ * @return string representation of error_code
+ */
+std::string GetErrorString(int error_code);
+
 }  // namespace tools
 }  // namespace common