summaryrefslogtreecommitdiff
path: root/tools/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/utils.c')
-rw-r--r--tools/utils.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/utils.c b/tools/utils.c
index 691070e..3895215 100644
--- a/tools/utils.c
+++ b/tools/utils.c
@@ -2,6 +2,7 @@
#include <sstream>
#include <iomanip>
#include <stdlib.h> /* for abs() */
+#include <string.h> /* for strerror_r() */
///// <cmath> would not be an improvement
///// due to lack of interger abs()
///// and ambiguous (and inefficient) promotion
@@ -124,3 +125,21 @@ string join(const string sep, const list<string> stuff){
}
return rslt;
}
+
+string strError(const int errnum){
+ char buf[1000];
+ char* rslt = strerror_r(errnum, buf, sizeof(buf));
+ return rslt;
+#ifdef XSI_not_gnu
+ if (rslt) {
+ cerr << "strerror_r() failed: " << rslt << " "
+ perror(0);
+ exit(1);
+ }
+#endif
+}
+
+extern int errno;
+string strError(){
+ return strError(errno);
+}