diff --git a/Jamfile b/Jamfile index e194a3a71..b0e34a217 100755 --- a/Jamfile +++ b/Jamfile @@ -120,6 +120,11 @@ rule linking ( properties * ) result += librt ; } + if on in $(properties) + { + result += libiconv ; + } + if yes in $(properties) { result += tcmalloc ; @@ -233,6 +238,10 @@ feature need-librt : no yes : composite propagated link-incompatible ; feature fiemap : off on : composite propagated ; feature.compose on : HAVE_LINUX_FIEMAP_H ; +feature iconv : auto on off : composite propagated ; +feature.compose on : TORRENT_USE_ICONV=1 ; +feature.compose off : TORRENT_USE_ICONV=0 ; + feature full-stats : on off : composite propagated link-incompatible ; feature.compose off : TORRENT_DISABLE_FULL_STATS ; @@ -328,6 +337,9 @@ lib gdi32 : : gdi32 ; # required for networking on beos lib netkit : : net /boot/system/lib shared ; +# when using iconv +lib libiconv : : iconv shared ; + local boost-library-search-path = /opt/local/lib /usr/lib diff --git a/docs/building.rst b/docs/building.rst index 3e0fe3e96..1bfc10cad 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -357,6 +357,12 @@ Build features: | | * ``off`` - only collects the standard stats for | | | upload and download rate. | +--------------------------+----------------------------------------------------+ +| ``iconv`` | * ``auto`` - use iconv for string conversions for | +| | linux and mingw and other posix platforms. | +| | * ``on`` - force use of iconv | +| | * ``off`` - force not using iconv (disables locale | +| | awareness except on windows). | ++--------------------------+----------------------------------------------------+ .. _MaxMind: http://www.maxmind.com/app/api diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 725566bc7..0c69543e7 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -121,7 +121,9 @@ POSSIBILITY OF SUCH DAMAGE. // (disables some float-dependent APIs) #define TORRENT_NO_FPU 1 #define TORRENT_USE_I2P 0 +#ifndef TORRENT_USE_ICONV #define TORRENT_USE_ICONV 0 +#endif // ==== Darwin/BSD === #elif (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __NetBSD__ \ @@ -131,8 +133,10 @@ POSSIBILITY OF SUCH DAMAGE. // we don't need iconv on mac, because // the locale is always utf-8 #if defined __APPLE__ +#ifndef TORRENT_USE_ICONV #define TORRENT_USE_ICONV 0 #endif +#endif #define TORRENT_HAS_FALLOCATE 0 // ==== LINUX === @@ -143,7 +147,9 @@ POSSIBILITY OF SUCH DAMAGE. #elif defined __MINGW32__ #define TORRENT_MINGW #define TORRENT_WINDOWS +#ifndef TORRENT_USE_ICONV #define TORRENT_USE_ICONV 1 +#endif #define TORRENT_USE_RLIMIT 0 // ==== WINDOWS === @@ -152,7 +158,9 @@ POSSIBILITY OF SUCH DAMAGE. // windows has its own functions to convert // apple uses utf-8 as its locale, so no conversion // is necessary +#ifndef TORRENT_USE_ICONV #define TORRENT_USE_ICONV 0 +#endif #define TORRENT_USE_RLIMIT 0 #define TORRENT_HAS_FALLOCATE 0 @@ -167,7 +175,9 @@ POSSIBILITY OF SUCH DAMAGE. #include // B_PATH_NAME_LENGTH #define TORRENT_HAS_FALLOCATE 0 #define TORRENT_USE_MLOCK 0 +#ifndef TORRENT_USE_ICONV #define TORRENT_USE_ICONV 0 +#endif #if __GNUCC__ == 2 # if defined(TORRENT_BUILDING_SHARED) # define TORRENT_EXPORT __declspec(dllexport) diff --git a/src/escape_string.cpp b/src/escape_string.cpp index b2c1376ce..c80598334 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -620,13 +620,8 @@ namespace libtorrent ret.resize(outsize); char const* in = s.c_str(); char* out = &ret[0]; -#ifdef TORRENT_LINUX -// linux (and posix) seems to have a weird iconv signature -#define ICONV_IN_CAST (char**) -#else -#define ICONV_IN_CAST -#endif - size_t retval = iconv(h, ICONV_IN_CAST &in, &insize, + // posix has a weird iconv signature + size_t retval = iconv(h, (char**)&in, &insize, &out, &outsize); if (retval == (size_t)-1) return s; // if this string has an invalid utf-8 sequence in it, don't touch it