diff --git a/Makefile.in b/Makefile.in index fe666f5..8ce0f17 100644 --- a/Makefile.in +++ b/Makefile.in @@ -29,6 +29,7 @@ SOURCE=\ base/base64.cc \ base/endian_utils.cc \ base/error_state.cc \ + base/error_string.cc \ base/progress_monitor.cc \ base/xml_utils.cc \ block-cache/block_cache.cc \ @@ -98,6 +99,7 @@ CFLAGS+=-g -Wall -O3 CXXFLAGS+=-g -Wall -fno-strict-aliasing CXXFLAGS+=@CXXOPTIMISE_FLAG@ CXXFLAGS+=@CXXDEBUG_FLAG@ +CXXFLAGS+=@CXX_STRERROR_FLAG@ INCLUDES+=-I$(TOP_BUILDDIR) -I$(TOP_DIR) -I$(TOP_DIR)/thin-provisioning LIBS:=-lstdc++ -laio -lexpat INSTALL:=@INSTALL@ diff --git a/caching/cache_check.cc b/caching/cache_check.cc index 400b214..ba750d5 100644 --- a/caching/cache_check.cc +++ b/caching/cache_check.cc @@ -13,6 +13,7 @@ #include #include "base/error_state.h" +#include "base/error_string.h" #include "base/nested_output.h" #include "caching/commands.h" #include "caching/metadata.h" @@ -202,10 +203,7 @@ namespace { int r = ::stat(path.c_str(), &info); if (r) { ostringstream msg; - char buffer[128], *ptr; - - ptr = ::strerror_r(errno, buffer, sizeof(buffer)); - msg << path << ": " << ptr; + msg << path << ": " << error_string(errno); throw runtime_error(msg.str()); } diff --git a/configure.ac b/configure.ac index f15906b..3e6c6a9 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,13 @@ AC_PROG_MAKE_SET AC_PROG_MKDIR_P AC_PROG_INSTALL +################################################################ +dnl -- Checks for functions. +AC_FUNC_STRERROR_R +if test x$ac_cv_func_strerror_r_char_p = xyes; then + CXX_STRERROR_FLAG="-DSTRERROR_R_CHAR_P" +fi + ################################################################################ dnl -- Prefix is /usr by default, the exec_prefix default is setup later AC_PREFIX_DEFAULT(/usr) @@ -136,6 +143,7 @@ VERSION_PATCHLEVEL=`echo "$VER" | $AWK -F '[[(.]]' '{print $3}'` ################################################################ AC_SUBST(CXXDEBUG_FLAG) AC_SUBST(CXXOPTIMISE_FLAG) +AC_SUBST(CXX_STRERROR_FLAG) AC_SUBST(INSTALL) AC_SUBST(prefix) AC_SUBST(RELEASE_DATE) diff --git a/era/era_check.cc b/era/era_check.cc index fed199e..d64999d 100644 --- a/era/era_check.cc +++ b/era/era_check.cc @@ -13,6 +13,7 @@ #include #include "base/error_state.h" +#include "base/error_string.h" #include "base/nested_output.h" #include "era/commands.h" #include "era/writeset_tree.h" @@ -186,10 +187,7 @@ namespace { int r = ::stat(path.c_str(), &info); if (r) { ostringstream msg; - char buffer[128], *ptr; - - ptr = ::strerror_r(errno, buffer, sizeof(buffer)); - msg << path << ": " << ptr; + msg << path << ": " << error_string(errno);; throw runtime_error(msg.str()); } diff --git a/persistent-data/block.tcc b/persistent-data/block.tcc index f2f3a7a..529f7af 100644 --- a/persistent-data/block.tcc +++ b/persistent-data/block.tcc @@ -18,13 +18,14 @@ #include "block.h" +#include "base/error_string.h" + #include #include #include #include #include #include -#include #include #include @@ -44,11 +45,8 @@ namespace { // FIXME: introduce a new exception for this, or at least lift this // to exception.h void syscall_failed(char const *call) { - char buffer[128]; - char *msg = strerror_r(errno, buffer, sizeof(buffer)); - ostringstream out; - out << "syscall '" << call << "' failed: " << msg; + out << "syscall '" << call << "' failed: " << base::error_string(errno);; throw runtime_error(out.str()); }