using namespace std; #include #include /* for getenv() */ #include /* for strerror_r */ #include "strlib.h" #include #include /* for snprintf() */ string ltrim(const string foo, const string strip){ size_t where = foo.find_first_not_of(strip); if (where == foo.npos) return foo; return foo.substr(where); } string rtrim(const string foo, const string strip){ size_t where = foo.find_last_not_of(strip); if (where == foo.npos) return ""; return foo.substr(0, where+1); } string trim(const string foo, const string bar){ return ltrim(rtrim(foo, bar), bar); } string Getenv(const string foo, const string dflt){ char* bar = getenv(foo.c_str()); if (!bar) return dflt; return bar; } string Strerror(const int errcode){ const int sz(100); char buf[sz]; char* rslt = strerror_r(errcode, buf, sz); if (rslt) return buf; snprintf(buf, 20, "%19d", errcode); return string("unknown error code: ") + buf; } string Strerror(){ return strerror(errno); }