1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Added build option WITH_ICONV.

Default is OFF, which means MariaDB Connector/C
will be built without iconv support.

If set to OFF The API function mariadb_convert_string will always
return -1 and errorcode ENOTSUP.
This commit is contained in:
Georg Richter
2020-09-14 12:01:06 +02:00
parent ed9a6d419d
commit 7052619cc4
4 changed files with 27 additions and 6 deletions

View File

@@ -24,7 +24,7 @@ get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)
# do not inherit include directories from the parent project # do not inherit include directories from the parent project
SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES) SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS
WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL WITH_ICONV
INSTALL_LAYOUT WITH_TEST_SRCPKG) INSTALL_LAYOUT WITH_TEST_SRCPKG)
SET(${V} ${${OPT}${V}}) SET(${V} ${${OPT}${V}})
ENDFOREACH() ENDFOREACH()
@@ -57,6 +57,7 @@ ELSE()
ADD_OPTION(WITH_MSI "Build MSI installation package" OFF) ADD_OPTION(WITH_MSI "Build MSI installation package" OFF)
ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF) ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF)
ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF) ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF)
ADD_OPTION(WITH_ICONV "enables character set conversion" OFF)
ENDIF() ENDIF()
ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON) ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON)
@@ -343,8 +344,10 @@ ELSEIF (NOT ENABLED_LOCAL_INFILE MATCHES "^(ON|OFF|AUTO)$")
MESSAGE(FATAL_ERROR "ENABLED_LOCAL_INFILE must be one of OFF, ON, AUTO") MESSAGE(FATAL_ERROR "ENABLED_LOCAL_INFILE must be one of OFF, ON, AUTO")
ENDIF() ENDIF()
IF(NOT WIN32) IF(WITH_ICONV)
INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake) IF(NOT WIN32)
INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake)
ENDIF()
ENDIF() ENDIF()
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in

View File

@@ -58,6 +58,7 @@ if (ICONV_FOUND)
return 0; return 0;
} }
" ICONV_SECOND_ARGUMENT_IS_CONST ) " ICONV_SECOND_ARGUMENT_IS_CONST )
ADD_DEFINITIONS(-DHAVE_ICONV)
endif (ICONV_FOUND) endif (ICONV_FOUND)
set (CMAKE_REQUIRED_INCLUDES) set (CMAKE_REQUIRED_INCLUDES)

View File

@@ -53,11 +53,13 @@
#include <mariadb_ctype.h> #include <mariadb_ctype.h>
#include <ma_string.h> #include <ma_string.h>
#ifdef HAVE_ICONV
#ifdef _WIN32 #ifdef _WIN32
#include "../win-iconv/iconv.h" #include "../win-iconv/iconv.h"
#else #else
#include <iconv.h> #include <iconv.h>
#endif #endif
#endif
#if defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE) #if defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE)
@@ -1385,7 +1387,7 @@ int madb_get_windows_cp(const char *charset)
#endif #endif
/* }}} */ /* }}} */
#ifdef HAVE_ICONV
/* {{{ map_charset_name /* {{{ map_charset_name
Changing charset name into something iconv understands, if necessary. Changing charset name into something iconv understands, if necessary.
Another purpose it to avoid BOMs in result string, adding BE if necessary Another purpose it to avoid BOMs in result string, adding BE if necessary
@@ -1413,6 +1415,7 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe
} }
} }
/* }}} */ /* }}} */
#endif
/* {{{ mariadb_convert_string /* {{{ mariadb_convert_string
Converts string from one charset to another, and writes converted string to given buffer Converts string from one charset to another, and writes converted string to given buffer
@@ -1426,9 +1429,17 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe
@return -1 in case of error, bytes used in the "to" buffer, otherwise @return -1 in case of error, bytes used in the "to" buffer, otherwise
*/ */
size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs, size_t STDCALL mariadb_convert_string(const char *from __attribute__((unused)),
char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode) size_t *from_len __attribute__((unused)),
MARIADB_CHARSET_INFO *from_cs __attribute__((unused)),
char *to __attribute__((unused)),
size_t *to_len __attribute__((unused)),
MARIADB_CHARSET_INFO *to_cs __attribute__((unused)), int *errorcode)
{ {
#ifndef HAVE_ICONV
*errorcode= ENOTSUP;
return -1;
#else
iconv_t conv= 0; iconv_t conv= 0;
size_t rc= -1; size_t rc= -1;
size_t save_len= *to_len; size_t save_len= *to_len;
@@ -1462,6 +1473,7 @@ error:
if (conv != (iconv_t)-1) if (conv != (iconv_t)-1)
iconv_close(conv); iconv_close(conv);
return rc; return rc;
#endif
} }
/* }}} */ /* }}} */

View File

@@ -661,6 +661,10 @@ static int test_bug_54100(MYSQL *mysql)
static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused))) static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused)))
{ {
#ifndef HAVE_ICONV
diag("MariaDB Connector/C was built without iconv support");
return SKIP;
#else
const char *csname[]= {"utf16", "utf16le", "utf32", "utf8"}; const char *csname[]= {"utf16", "utf16le", "utf32", "utf8"};
MARIADB_CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)]; MARIADB_CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)];
@@ -724,6 +728,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused)))
} }
return OK; return OK;
#endif
} }
static int charset_auto(MYSQL *my __attribute__((unused))) static int charset_auto(MYSQL *my __attribute__((unused)))