From 4134b154839c91f44bb39547af9297f4b6a353d3 Mon Sep 17 00:00:00 2001 From: John Denker Date: Fri, 23 Nov 2012 11:51:38 -0800 Subject: pipette ... for playing around with pipes and other i/o stuff --- tools/utils.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tools/utils.c') 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 #include #include /* for abs() */ +#include /* for strerror_r() */ ///// 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 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); +} -- cgit v1.2.3