Forgot error_string.h/cc from previous commit
This commit is contained in:
parent
25b4b526f4
commit
408b38a0f8
39
base/error_string.cc
Normal file
39
base/error_string.cc
Normal file
@ -0,0 +1,39 @@
|
||||
#include "base/error_string.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
#ifdef STRERROR_R_CHAR_P
|
||||
|
||||
string base::error_string(int err)
|
||||
{
|
||||
char *ptr;
|
||||
char buffer[128];
|
||||
|
||||
ptr = strerror_r(errno, buffer, sizeof(buffer));
|
||||
return string(ptr);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
string base::error_string(int err)
|
||||
{
|
||||
int r;
|
||||
char buffer[128];
|
||||
|
||||
r = strerror_r(errno, buffer, sizeof(buffer));
|
||||
if (r)
|
||||
throw runtime_error("strerror_r failed");
|
||||
|
||||
return string(buffer);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------
|
16
base/error_string.h
Normal file
16
base/error_string.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef BASE_ERROR_STRING_H
|
||||
#define BASE_ERROR_STRING_H
|
||||
|
||||
#include <string>
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace base {
|
||||
// There are a couple of version of strerror_r kicking around, so
|
||||
// we wrap it.
|
||||
std::string error_string(int err);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user