diff options
author | John Denker <jsd@av8n.com> | 2012-11-23 11:51:38 -0800 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-11-23 11:51:38 -0800 |
commit | 4134b154839c91f44bb39547af9297f4b6a353d3 (patch) | |
tree | f8b7bee0f7596f3db63a4f44cb8a0f2dc2dfd5e9 /tools/utils.c | |
parent | 2db619bf6bb01efdc01ce9b3729575ae21abcf5f (diff) |
pipette ... for playing around with pipes and other i/o stuff
Diffstat (limited to 'tools/utils.c')
-rw-r--r-- | tools/utils.c | 19 |
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); +} |