diff --git a/config/config.h.cmake b/config/config.h.cmake index 6cce989e..3471c483 100644 --- a/config/config.h.cmake +++ b/config/config.h.cmake @@ -25,8 +25,8 @@ // Define if you want video support. #cmakedefine EXV_ENABLE_VIDEO -// Define if you have correct declaration of strerror_r(). -#cmakedefine EXV_HAVE_DECL_STRERROR_R +// Define if you have the strerror_r function. +#cmakedefine EXV_HAVE_STRERROR_R // Define to enable the Windows unicode path support. #cmakedefine EXV_UNICODE_PATH @@ -57,15 +57,6 @@ #endif #endif -// Define if you have the strerror function. -#cmakedefine EXV_HAVE_STRERROR - -// Define if you have the strerror_r function. -#cmakedefine EXV_HAVE_STRERROR_R - -// Define if strerror_r returns char *. -#cmakedefine STRERROR_R_CHAR_P - // Define if you have the header file. #cmakedefine EXV_HAVE_STRINGS_H diff --git a/config/generateConfigFile.cmake b/config/generateConfigFile.cmake index 69a30493..fefb2cad 100644 --- a/config/generateConfigFile.cmake +++ b/config/generateConfigFile.cmake @@ -22,12 +22,9 @@ set(EXV_UNICODE_PATH ${EXIV2_ENABLE_WIN_UNICODE}) check_function_exists( gmtime_r EXV_HAVE_GMTIME_R ) check_function_exists( mmap EXV_HAVE_MMAP ) check_function_exists( munmap EXV_HAVE_MUNMAP ) -check_function_exists( strerror EXV_HAVE_STRERROR ) check_function_exists( strerror_r EXV_HAVE_STRERROR_R ) check_function_exists( timegm EXV_HAVE_TIMEGM ) -# TODO : Do something about EXV_STRERROR_R_CHAR_P - # TODO: This check should be removed and rely on the check done in findDependencies.cmake check_include_file( "libintl.h" EXV_HAVE_LIBINTL_H ) check_include_file( "unistd.h" EXV_HAVE_UNISTD_H ) @@ -46,20 +43,4 @@ if (NOT EXV_HAVE_LIBINTL_H) set(EXV_ENABLE_NLS 0) endif() - -include(CheckCSourceCompiles) -##################################################################################### -# strerror_r returns char* - -# NOTE : reverting commit #2041, which break compilation under linux and windows - -CHECK_C_SOURCE_COMPILES( "#include -int main() { -char * c; -c = strerror_r(0,c,0); -return 0; -}" EXV_HAVE_DECL_STRERROR_R ) - -##################################################################################### - configure_file( config/config.h.cmake ${CMAKE_BINARY_DIR}/exv_conf.h @ONLY) diff --git a/include/exiv2/config.h b/include/exiv2/config.h index 54b6503e..c1352d41 100644 --- a/include/exiv2/config.h +++ b/include/exiv2/config.h @@ -144,11 +144,6 @@ typedef int pid_t; ///// End symbol visibility ///////// ///// Start of platform marcos ///////// -// Linux GCC 4.8 appears to be confused about strerror_r -#if !defined(EXV_STRERROR_R_CHAR_P) && defined( __gnu_linux__) && defined(__GLIBC__) -#define EXV_STRERROR_R_CHAR_P -#endif - #if defined(__MINGW32__) || defined(__MINGW64__) # ifndef __MING__ # define __MING__ 1 diff --git a/include/exiv2/exv_msvc.h b/include/exiv2/exv_msvc.h index 48c4f759..28b6d0e1 100644 --- a/include/exiv2/exv_msvc.h +++ b/include/exiv2/exv_msvc.h @@ -14,10 +14,6 @@ /* Define to 1 if you have the `alarm' function. */ /* #undef EXV_HAVE_ALARM */ -/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you - don't. */ -/* #undef EXV_HAVE_DECL_STRERROR_R */ - /* Define to 1 if you have the `gmtime_r' function. */ /* #undef EXV_HAVE_GMTIME_R */ @@ -82,8 +78,8 @@ /* Define to 1 if you have the header file. */ /* #undef EXV_HAVE_STDINT_H */ -/* Define to 1 if you have the `strerror' function. */ -#define EXV_HAVE_STRERROR 1 +/* Define to 1 if you have the header file. */ +/* #undef EXV_HAVE_STDLIB_H */ /* Define to 1 if you have the `strerror_r' function. */ /* #undef EXV_HAVE_STRERROR_R */ diff --git a/src/futils.cpp b/src/futils.cpp index 00571aed..525c4185 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -29,6 +29,7 @@ #include "config.h" #include "futils.hpp" +#include "enforce.hpp" // + standard includes #include @@ -46,12 +47,12 @@ #include #include -#if defined EXV_HAVE_STRERROR_R && !defined EXV_HAVE_DECL_STRERROR_R -# ifdef EXV_STRERROR_R_CHAR_P +#ifdef EXV_HAVE_STRERROR_R +#ifdef _GNU_SOURCE extern char *strerror_r(int errnum, char *buf, size_t n); -# else +#else extern int strerror_r(int errnum, char *buf, size_t n); -# endif +#endif #endif namespace Exiv2 { @@ -331,27 +332,30 @@ namespace Exiv2 { else return path.substr(found); } #endif + std::string strError() { int error = errno; std::ostringstream os; #ifdef EXV_HAVE_STRERROR_R const size_t n = 1024; -// _GNU_SOURCE: See Debian bug #485135 -# if defined EXV_STRERROR_R_CHAR_P && defined _GNU_SOURCE +#ifdef _GNU_SOURCE char *buf = 0; char buf2[n]; std::memset(buf2, 0x0, n); buf = strerror_r(error, buf2, n); -# else +#else char buf[n]; std::memset(buf, 0x0, n); - strerror_r(error, buf, n); -# endif + const int ret = strerror_r(error, buf, n); + enforce(ret != ERANGE, Exiv2::kerCallFailed); +#endif os << buf; // Issue# 908. // report strerror() if strerror_r() returns empty - if ( !buf[0] ) os << strerror(error); + if ( !buf[0] ) { + os << strerror(error); + } #else os << std::strerror(error); #endif diff --git a/src/version.cpp b/src/version.cpp index d5ca1b11..362c5b30 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -259,7 +259,6 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) int have_stdint =0; int have_stdlib =0; int have_strlib =0; - int have_strerror =0; int have_strerror_r =0; int have_strings_h =0; int have_mmap =0; @@ -326,10 +325,6 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) have_stdlib=1; #endif -#ifdef EXV_HAVE_STRERROR - have_strerror=1; -#endif - #ifdef EXV_HAVE_STRERROR_R have_strerror_r=1; #endif @@ -500,7 +495,6 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) output(os,keys,"have_stdint" ,have_stdint ); output(os,keys,"have_stdlib" ,have_stdlib ); output(os,keys,"have_strlib" ,have_strlib ); - output(os,keys,"have_strerror" ,have_strerror ); output(os,keys,"have_strerror_r" ,have_strerror_r ); output(os,keys,"have_strings_h" ,have_strings_h ); output(os,keys,"have_mmap" ,have_mmap );